@graphql-codegen/plugin-helpers
Version:
GraphQL Code Generator common utils and types
119 lines (118 loc) • 3.95 kB
text/typescript
import { DirectiveNode, FieldDefinitionNode, GraphQLNamedType, GraphQLSchema } from 'graphql';
/**
* Federation Spec
*/
export declare const federationSpec: import("graphql").DocumentNode;
/**
* ReferenceSelectionSet
* @description Each is a collection of fields that are available in a reference payload (originated from the Router)
* @example
* - resolvable fields marked with `@key`
* - fields declared in `@provides`
*/
interface ReferenceSelectionSet {
name: string;
selection: boolean | ReferenceSelectionSet[];
}
interface TypeMeta {
hasResolveReference: boolean;
resolvableKeyDirectives: readonly DirectiveNode[];
/**
* referenceSelectionSets
* @description Each element can be `ReferenceSelectionSet[]`.
* Elements at the root level are combined with `&` and nested elements are combined with `|`.
*
* @example:
* - [[A, B], [C], [D]] -> (A | B) & C & D
* - [[A, B], [C, D], [E]] -> (A | B) & (C | D) & E
*/
referenceSelectionSets: ReferenceSelectionSet[][];
}
export type FederationMeta = {
[typeName: string]: TypeMeta;
};
/**
* Adds `__resolveReference` in each ObjectType and InterfaceType involved in Federation.
* We do this to utilise the existing FieldDefinition logic of the plugin, which includes many logic:
* - mapper
* - return type
* @param schema
*/
export declare function addFederationReferencesToSchema(schema: GraphQLSchema): {
transformedSchema: GraphQLSchema;
federationMeta: FederationMeta;
};
/**
* Removes Federation Spec from GraphQL Schema
* @param schema
* @param config
*/
export declare function removeFederation(schema: GraphQLSchema): GraphQLSchema;
export declare class ApolloFederation {
private enabled;
private schema;
private providesMap;
protected meta: FederationMeta;
constructor({ enabled, schema, meta }: {
enabled: boolean;
schema: GraphQLSchema;
meta: FederationMeta;
});
/**
* Excludes types definde by Federation
* @param typeNames List of type names
*/
filterTypeNames(typeNames: string[]): string[];
/**
* Excludes `__resolveReference` fields
* @param fieldNames List of field names
*/
filterFieldNames(fieldNames: string[]): string[];
/**
* Decides if directive should not be generated
* @param name directive's name
*/
skipDirective(name: string): boolean;
/**
* Decides if scalar should not be generated
* @param name directive's name
*/
skipScalar(name: string): boolean;
/**
* Decides if field should not be generated
* @param data
*/
skipField({ fieldNode, parentType }: {
fieldNode: FieldDefinitionNode;
parentType: GraphQLNamedType;
}): boolean;
isResolveReferenceField(fieldNode: FieldDefinitionNode): boolean;
/**
* Transforms a field's ParentType signature in ObjectTypes or InterfaceTypes involved in Federation
*/
transformFieldParentType({ fieldNode, parentType, parentTypeSignature, federationTypeSignature, }: {
fieldNode: FieldDefinitionNode;
parentType: GraphQLNamedType;
parentTypeSignature: string;
federationTypeSignature: string;
}): string;
addFederationTypeGenericIfApplicable({ genericTypes, typeName, federationTypesType, }: {
genericTypes: string[];
typeName: string;
federationTypesType: string;
}): void;
getMeta(): FederationMeta;
private isExternalAndNotProvided;
private isExternal;
private hasProvides;
printReferenceSelectionSet({ typeName, referenceSelectionSet, }: {
typeName: string;
referenceSelectionSet: ReferenceSelectionSet;
}): string;
printReferenceSelectionSets({ typeName, baseFederationType, }: {
typeName: string;
baseFederationType: string;
}): string | false;
private createMapOfProvides;
}
export {};