How to use the @graphql-codegen/plugin-helpers.addFederationReferencesToSchema function in @graphql-codegen/plugin-helpers

To help you get started, we’ve selected a few @graphql-codegen/plugin-helpers 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 dotansimha / graphql-code-generator / packages / plugins / typescript / resolvers / src / index.ts View on Github external
export const plugin: PluginFunction = (schema: GraphQLSchema, documents: Types.DocumentFile[], config: TypeScriptResolversPluginConfig) => {
  const imports = [];
  if (!config.customResolveInfo) {
    imports.push('GraphQLResolveInfo');
  }
  const showUnusedMappers = typeof config.showUnusedMappers === 'boolean' ? config.showUnusedMappers : true;
  const noSchemaStitching = typeof config.noSchemaStitching === 'boolean' ? config.noSchemaStitching : false;

  if (config.noSchemaStitching === false) {
    console['warn'](`The default behavior of 'noSchemaStitching' will be reversed in the next major release. Support for Schema Stitching will be disabled by default.`);
  }

  const indexSignature = config.useIndexSignature ? ['export type WithIndex = TObject & Record;', 'export type ResolversObject = WithIndex;'].join('\n') : '';

  const transformedSchema = config.federation ? addFederationReferencesToSchema(schema) : schema;
  const visitor = new TypeScriptResolversVisitor(config, transformedSchema);

  const printedSchema = config.federation ? printSchemaWithDirectives(transformedSchema) : printSchema(transformedSchema);
  const astNode = parse(printedSchema);
  // runs visitor
  const visitorResult = visit(astNode, { leave: visitor });

  const defsToInclude = [];
  const stitchingResolverType = `
export type StitchingResolver = {
  fragment: string;
  resolve: ResolverFn;
};
`;
  const resolverType = `export type Resolver =`;
  const resolverFnUsage = `ResolverFn`;
github dotansimha / graphql-code-generator / packages / plugins / flow / resolvers / src / index.ts View on Github external
export const plugin: PluginFunction = (schema: GraphQLSchema, documents: Types.DocumentFile[], config: FlowResolversPluginConfig) => {
  const imports = ['type GraphQLResolveInfo'];
  const showUnusedMappers = typeof config.showUnusedMappers === 'boolean' ? config.showUnusedMappers : true;

  const gqlImports = `import { ${imports.join(', ')} } from 'graphql';`;

  const transformedSchema = config.federation ? addFederationReferencesToSchema(schema) : schema;

  const printedSchema = config.federation ? printSchemaWithDirectives(transformedSchema) : printSchema(transformedSchema);
  const astNode = parse(printedSchema);
  const visitor = new FlowResolversVisitor(config, transformedSchema);
  const visitorResult = visit(astNode, { leave: visitor });

  const defsToInclude: string[] = [visitor.getResolverTypeWrapperSignature()];

  if (visitor.hasFederation()) {
    defsToInclude.push(`
    export type ReferenceResolver = (
      reference: TReference,
      context: TContext,
      info: GraphQLResolveInfo
    ) => Promise | TResult;
    `);