How to use the graphql-tools.addResolveFunctionsToSchema 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 ember-graphql / ember-apollo-client / tests / dummy / app / instance-initializers / mock-graphql.js View on Github external
};
  let mocks = {
    // This is where you tell graphql-tools how to generate a mock for a custom
    // scalar type:
    //
    // Time() {
    //   return moment().utc().format('YYYY-MM-DDTHH:mm:ss.SSSZ');
    // }

    Date() {
      return '2019-09-28';
    },
  };

  let schema = makeExecutableSchema({ typeDefs: schemaString, resolvers });
  addResolveFunctionsToSchema({
    schema,
    resolvers: typeResolvers,
    inheritResolversFromInterfaces: true,
  });
  addMockFunctionsToSchema({ schema, mocks, preserveResolvers: true });

  let pretender = new Pretender();

  pretender.post('https://test.example/graphql', function(request) {
    let body = JSON.parse(request.requestBody);

    return graphql(schema, body.query, {}, {}, body.variables).then(result => {
      return [200, { 'Content-Type': 'application/json' }, result];
    });
  });
github olymp / olymp / packages / graphql / server / schema-builder / index.js View on Github external
});
          let value;
          onAfter.forEach((hook) => {
            promise = promise.then((newValue) => {
              value = newValue || value;
              return hook({ keys, source, value, variables, context, resolverAST, ast });
            });
          });
          return promise.then(newValue => newValue || value);
        };
      } else {
        store[key] = obj[key];
      } return store;
    }, {});
  };
  addResolveFunctionsToSchema(builtSchema, recurse(resolvers));
  // console.log(resolvers);
  return builtSchema;
};
github abhiaiyer91 / apollo-storybook-decorator / packages / apollo-storybook-v1 / src / index.js View on Github external
reduxMiddlewares = [],
  apolloClientOptions = {},
  typeResolvers,
  context = {},
  rootValue = {},
}) {
  const schema = makeExecutableSchema({ typeDefs });
  if (!!mocks) {
    addMockFunctionsToSchema({
      schema,
      mocks,
    });
  }

  if (!!typeResolvers) {
    addResolveFunctionsToSchema(schema, typeResolvers);
  }

  const graphqlClient = new ApolloClient({
    addTypename: true,
    networkInterface: {
      query(request) {
        return graphql(
          schema,
          print(request.query),
          rootValue,
          context,
          request.variables,
          request.operationName,
        );
      },
    },
github olymp / olymp / packages / graphql / server / utils / build-schema.js View on Github external
directives,
    resolvers,
    hooks
  );
  transformedAST.definitions
    .filter(x => x.kind === 'ObjectTypeDefinition')
    .forEach((definition) => {
      if (['Query', 'Mutation'].includes(definition.name.value)) { return; }
      const input = transformASTTypeToInput(definition, {
        newName: `${capitalize(definition.name.value)}Input`,
        ast: transformedAST,
      });
      addDefinition(transformedAST, input);
    });
  const builtSchema = buildASTSchema(transformedAST);
  addResolveFunctionsToSchema(builtSchema, resolvers);
  return { schema: builtSchema, ast: transformedAST };
};
github prisma-labs / graphql-middleware / src / middleware.ts View on Github external
options: IApplyOptions,
  middleware: IMiddleware,
): {
  schema: GraphQLSchema
  fragmentReplacements: FragmentReplacement[]
} {
  const validMiddleware = validateMiddleware(schema, middleware)
  const resolvers = generateResolverFromSchemaAndMiddleware(
    schema,
    options,
    validMiddleware,
  )

  const fragmentReplacements = extractFragmentReplacements(resolvers)

  addResolveFunctionsToSchema({
    schema,
    resolvers,
    resolverValidationOptions: {
      requireResolversForResolveType: false,
    },
  })

  return { schema, fragmentReplacements }
}
github prisma-archive / graphql-schema-cache / src / Remote / utils.ts View on Github external
}

  typeRegistry.addType('Query', query);
  typeRegistry.addType('Mutation', mutation);

  let mergedSchema = new GraphQLSchema({
    query,
    mutation,
    types: typeRegistry.getAllTypes(),
  });

  extensions.forEach(extension => {
    mergedSchema = extendSchema(mergedSchema, extension);
  });

  addResolveFunctionsToSchema(mergedSchema, fullResolvers);

  return mergedSchema;
}
github exogen / graphbrainz / src / schema.js View on Github external
export function applyExtension(extension, schema, options = {}) {
  let outputSchema = schema
  if (extension.extendSchema) {
    if (typeof extension.extendSchema === 'object') {
      debug(
        `Extending schema via an object from the “${extension.name}” extension.`
      )
      const { schemas = [], resolvers } = extension.extendSchema
      outputSchema = schemas.reduce((updatedSchema, extensionSchema) => {
        if (typeof extensionSchema === 'string') {
          extensionSchema = parse(extensionSchema)
        }
        return extendSchema(updatedSchema, extensionSchema)
      }, outputSchema)
      if (resolvers) {
        addResolveFunctionsToSchema({ schema: outputSchema, resolvers })
      }
    } else if (typeof extension.extendSchema === 'function') {
      debug(
        `Extending schema via a function from the “${
          extension.name
        }” extension.`
      )
      outputSchema = extension.extendSchema(schema, options)
    } else {
      throw new Error(
        `The “${extension.name}” extension contains an invalid ` +
          `\`extendSchema\` value: ${extension.extendSchema}`
      )
    }
  }
github abhiaiyer91 / apollo-storybook-decorator / packages / apollo-storybook-core / src / index.js View on Github external
}) {
  const schema = makeExecutableSchema({ typeDefs, resolverValidationOptions });

  let mockOptions = {};

  if (!!mocks) {
    mockOptions = {
      schema,
      mocks,
    };

    addMockFunctionsToSchema(mockOptions);
  }

  if (!!typeResolvers) {
    addResolveFunctionsToSchema({ schema, resolvers: typeResolvers });
  }

  const cache = new InMemoryCache(cacheOptions);

  return new ApolloClient({
    addTypename: true,
    cache,
    link: ApolloLink.from([
      ...links(cache),
      createLink(schema, rootValue, context, apolloLinkOptions),
    ]),
    connectToDevTools: true,
    ...apolloClientOptions,
  });
}
github genie-team / graphql-genie / src / graphQLShema.ts View on Github external
export const addResolvers = (typeName: string, fieldResolvers: Map> ): GraphQLSchema  => {
	const resolverMap = {};
	resolverMap[typeName] = {};
	for (const [name, resolve] of fieldResolvers) {
		resolverMap[typeName][name] = resolve;
	}

	addResolveFunctionsToSchema(schema, resolverMap);
	return schema;
};