How to use the graphql-compose.ObjectTypeComposer.createTemp function in graphql-compose

To help you get started, we’ve selected a few graphql-compose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graphql-compose / graphql-compose-pagination / src / preparePaginationType.js View on Github external
/* @flow */
/* eslint-disable arrow-body-style */

import { upperFirst, ObjectTypeComposer, type SchemaComposer } from 'graphql-compose';

// PaginationInfo should be global
const PaginationInfoTC = ObjectTypeComposer.createTemp(`
# Information about pagination.
type PaginationInfo {
  # Current page number
  currentPage: Int!
  
  # Number of items per page
  perPage: Int!
  
  # Total number of pages
  pageCount: Int
  
  # Total number of items
  itemCount: Int
  
  # When paginating forwards, are there more items?
  hasNextPage: Boolean
github graphql-compose / graphql-compose-elasticsearch / src / ElasticApiParser.js View on Github external
Object.keys(fields).forEach(k => {
      const names = k.split('.');
      if (names.length === 1) {
        result[names[0]] = fields[k];
      } else {
        if (!result[names[0]]) {
          result[names[0]] = {
            type: ObjectTypeComposer.createTemp({
              name: `${this.prefix}_${upperFirst(names[0])}`,
              fields: (() => {}: any),
            }),
            resolve: () => {
              return {};
            },
          };
        }
        result[names[0]].type.setField(names[1], fields[k]);
      }
    });
github gridsome / gridsome / gridsome / lib / graphql / createSchema.js View on Github external
function createType (schemaComposer, type, options) {
  switch (type) {
    case CreatedGraphQLType.Object: {
      convertExtensionsToDirectives(options)
      return ObjectTypeComposer.createTemp(options, schemaComposer)
    }
    case CreatedGraphQLType.Union:
      return UnionTypeComposer.createTemp(options, schemaComposer)

    case CreatedGraphQLType.Input:
      return InputTypeComposer.createTemp(options, schemaComposer)

    case CreatedGraphQLType.Scalar:
      return ScalarTypeComposer.createTemp(options, schemaComposer)

    case CreatedGraphQLType.Interface:
      return InterfaceTypeComposer.createTemp(options, schemaComposer)

    case CreatedGraphQLType.Enum:
      return EnumTypeComposer.createTemp(options, schemaComposer)
  }
github gridsome / gridsome / gridsome / lib / graphql / createFieldTypes.js View on Github external
function createObjectType (schemaComposer, value, fieldName, prefix) {
  const name = createTypeName(prefix, fieldName)
  const fields = {}

  for (const key in value) {
    const options = value[key]
    const type = createFieldType(schemaComposer, options.value, key, name)

    if (type) {
      fields[options.fieldName] = type
    }
  }

  return !isEmpty(fields)
    ? { type: ObjectTypeComposer.createTemp({ name, fields }, schemaComposer) }
    : null
}
github graphql-compose / graphql-compose-connection / src / types / connectionType.js View on Github external
function createGlobalPageInfoType(name: string) {
  if (!globalPageInfoTypes[name]) {
    globalPageInfoTypes[name] = ObjectTypeComposer.createTemp(`
      """Information about pagination in a connection."""
      type ${name} {
        """When paginating forwards, are there more items?"""
        hasNextPage: Boolean!
        
        """When paginating backwards, are there more items?"""
        hasPreviousPage: Boolean!

        """When paginating backwards, the cursor to continue."""
        startCursor: String

        """When paginating forwards, the cursor to continue."""
        endCursor: String
      }
    `);
  }
github graphql-compose / graphql-compose-elasticsearch / src / elasticApiFieldConfig.js View on Github external
function instanceElasticClient(elasticClient: Object): GraphQLFieldConfig {
  const apiVersion = elasticClient.transport._config.apiVersion || DEFAULT_ELASTIC_API_VERSION;
  const prefix = `ElasticAPI${apiVersion.replace('.', '')}`;

  const apiParser = new ElasticApiParser({
    elasticClient,
    prefix,
  });

  return {
    description: `Elastic API v${apiVersion}`,
    type: ObjectTypeComposer.createTemp({
      name: prefix,
      fields: apiParser.generateFieldMap(),
    }).getType(),
    resolve: () => ({}),
  };
}
github graphql-compose / graphql-compose-json / src / ObjectParser.js View on Github external
static createTC(name: string, json: Object): ObjectTypeComposer {
    if (!json || typeof json !== 'object') {
      throw new Error('You provide empty object in second arg for `createTC` method.');
    }

    const tc = ObjectTypeComposer.createTemp(name);
    Object.keys(json).forEach(fieldName => {
      const fieldConfig = this.getFieldConfig(json[fieldName], { typeName: name, fieldName });
      tc.setField(fieldName, fieldConfig);
    });

    return tc;
  }