How to use the graphql-tools.buildSchemaFromTypeDefinitions function in graphql-tools

To help you get started, we’ve selected a few graphql-tools 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 apollographql / apollo-server / src / apolloServer.js View on Github external
}
        if (subtype === 'end') {
          // eslint-disable-next-line no-param-reassign
          intervalMap[supertype] = tstamp - intervalMap[supertype];
        }
      }

      let executableSchema;
      if (mocks) {
        // TODO: mocks doesn't yet work with a normal GraphQL schema, but it should!
        // have to rewrite these functions
        const myMocks = mocks || {};
        if (schema instanceof GraphQLSchema) {
          executableSchema = schema
        } else {
          executableSchema = buildSchemaFromTypeDefinitions(schema);
        }
        addResolveFunctionsToSchema(executableSchema, resolvers || {});
        addMockFunctionsToSchema({
          schema: executableSchema,
          mocks: myMocks,
          preserveResolvers: true,
        });
      } else {
        // this is just basics, makeExecutableSchema should catch the rest
        // TODO: should be able to provide a GraphQLschema and still use resolvers
        // and connectors if you want, but at the moment this is not possible.
        if (schema instanceof GraphQLSchema) {
          if (logger) {
            addErrorLoggingToSchema(schema, logger);
          }
          if (printErrors) {
github elastic / kibana / x-pack / plugins / infra / scripts / combined_schema.ts View on Github external
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */

import { buildSchemaFromTypeDefinitions } from 'graphql-tools';

import { schemas as serverSchemas } from '../server/graphql';

export const schemas = [...serverSchemas];

// this default export is used to feed the combined types to the gql-gen tool
// which generates the corresponding typescript types
// eslint-disable-next-line import/no-default-export
export default buildSchemaFromTypeDefinitions(schemas);
github elastic / kibana / x-pack / plugins / uptime / scripts / graphql_schemas.ts View on Github external
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */

import { buildSchemaFromTypeDefinitions } from 'graphql-tools';
import { typeDefs } from '../server/graphql';

export const schemas = [...typeDefs];

// this default export is used to feed the combined types to the gql-gen tool
// which generates the corresponding typescript types
// eslint-disable-next-line import/no-default-export
export default buildSchemaFromTypeDefinitions(schemas);
github elastic / kibana / x-pack / plugins / siem / scripts / combined_schema.ts View on Github external
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */

import { buildSchemaFromTypeDefinitions } from 'graphql-tools';

import { schemas as serverSchemas } from '../server/graphql';

export const schemas = [...serverSchemas];

// this default export is used to feed the combined types to the gql-gen tool
// which generates the corresponding typescript types
// eslint-disable-next-line import/no-default-export
export default buildSchemaFromTypeDefinitions(schemas);
github aws-amplify / amplify-cli / packages / amplify-appsync-simulator / src / schema / directives / auth.ts View on Github external
export function protectResolversWithAuthRules(typeDef, existingResolvers, simulator: AmplifyAppSyncSimulator) {
  const schema = buildSchemaFromTypeDefinitions(typeDef);
  const newResolverMap = {};
  forEachField(schema, (field, typeName, fieldName) => {
    const fieldResolver = getResolver(existingResolvers, typeName, fieldName);
    const allowedAuthTypes = getAuthDirectiveForField(schema, field, typeName, simulator);
    const allowedCognitoGroups = getAllowedCognitoGroups(schema, field, typeName);

    const newResolver = (root, args, ctx: AmplifyAppSyncSimulatorRequestContext, info: GraphQLResolveInfo) => {
      const currentAuthMode = ctx.requestAuthorizationMode;
      if (!allowedAuthTypes.includes(currentAuthMode)) {
        const err = new Unauthorized(`Not Authorized to access ${fieldName} on type ${typeName}`, info);
        throw err;
      }
      if (
        ctx.requestAuthorizationMode === AmplifyAppSyncSimulatorAuthenticationType.AMAZON_COGNITO_USER_POOLS &&
        allowedCognitoGroups.length
      ) {
github oscarhealth / graphql-mock-factory / src / server.js View on Github external
export function mockServer(
  schemaDefinition: string,
  mocks: MockMap = {},
  automocks = defaultAutomocks
) {
  const schema: GraphQLSchema = buildSchemaFromTypeDefinitions(
    schemaDefinition
  );

  if (automocks) {
    addAutomocks(schema, mocks, automocks);
  }

  validateMocks(mocks, schema);

  forEachField(schema, (type, field) => {
    field.resolve = getFieldResolver(type, field, mocks);
  });

  forEachInterface(schema, interfaceType => {
    interfaceType.resolveType = interfaceResolveType;
  });