Documentation
API Reference
Packages
federation

@graphql-tools/federation

Classes

Interfaces

Type Aliases

Variables

Functions

Type Aliases

FetchError

Ƭ FetchError: Object

Type declaration

NameTypeDescription
error{ code: string ; message: string }The fetch error reported by the up link. This means it’s not the local fetch error. Local fetch errors are thrown as exceptions.
error.codestring-
error.messagestring-
minDelaySecondsnumberThe minimum delay in seconds to wait before trying to fetch this supergraph again.

Defined in

packages/federation/src/managed-federation.ts:86


FetchSupergraphSdlFromManagedFederationOpts

Ƭ FetchSupergraphSdlFromManagedFederationOpts: Object

Type declaration

NameTypeDescription
apiKey?stringThe API key to use to authenticate with the managed federation up link. It needs at least the service:read permission. If not provided, APOLLO_KEY environment variable will be used instead. Learn how to create an API key
fetch?FetchFnThe fetch implementation to use. Default: global.fetch
graphRef?stringThe graph ref of the managed federation graph. It is composed of the graph ID and the variant (<YOUR_GRAPH_ID>@<VARIANT>). If not provided, APOLLO_GRAPH_REF environment variable is used. You can find a a graph’s ref at the top of its Schema Reference page in Apollo Studio.
lastSeenId?stringThe ID of the last fetched supergraph. If provided, a supergraph is returned only if the managed supergraph have changed.
loggerByMessageLevel?typeof DEFAULT_MESSAGE_LOGGERUp link can send back messages meant to be logged alongside the supergraph SDL. By default, the console is used.
upLink?stringThe URL of the managed federation up link. When retrying after a failure, you should cycle through the default up links using this option. Uplinks are available in DEFAULT_UPLINKS constant. This options can also be defined using the APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT environment variable. It should be a comma separated list of up links, but only the first one will be used. Default: ‘https://uplink.api.apollographql.com/’ (Apollo’s managed federation up link on GCP) Alternative: ‘https://aws.uplink.api.apollographql.com/’ (Apollo’s managed federation up link on AWS)

Defined in

packages/federation/src/managed-federation.ts:11


GetStitchedSchemaFromManagedFederationOpts

Ƭ GetStitchedSchemaFromManagedFederationOpts: FetchSupergraphSdlFromManagedFederationOpts & Omit<GetStitchedSchemaFromSupergraphSdlOpts, "supergraphSdl">

Defined in

packages/federation/src/managed-federation.ts:242


RouterConfig

Ƭ RouterConfig: Object

Type declaration

NameTypeDescription
idstringThe ID of the supergraph. Should be used as lastSeenId in the next fetch.
minDelaySecondsnumberThe minimum delay in seconds to wait before trying to fetch this supergraph again.
supergraphSdlstringThe supergraph SDL.

Defined in

packages/federation/src/managed-federation.ts:60


RouterConfigWithSchema

Ƭ RouterConfigWithSchema: RouterConfig & { schema: GraphQLSchema }

Defined in

packages/federation/src/managed-federation.ts:246


SupergraphSchemaManagerOptions

Ƭ SupergraphSchemaManagerOptions: Omit<GetStitchedSchemaFromManagedFederationOpts, "lastSeenId"> & { maxRetries?: number ; minDelaySeconds?: number ; retryDelaySeconds?: number }

Defined in

packages/federation/src/managed-federation.ts:297


Unchanged

Ƭ Unchanged: Object

Type declaration

NameTypeDescription
idstringThe ID of the supergraph. Should be used as lastSeenId in the next fetch.
minDelaySecondsnumberThe minimum delay in seconds to wait before trying to fetch this supergraph again.

Defined in

packages/federation/src/managed-federation.ts:75

Variables

DEFAULT_UPLINKS

Const DEFAULT_UPLINKS: string[]

The default managed federation up links. In case of failure, you should try to cycle through these up links.

The first one is Apollo’s managed federation up link on GCP, the second one is on AWS.

Defined in

packages/federation/src/managed-federation.ts:116


SubgraphBaseSDL

Const SubgraphBaseSDL: "\n scalar _Any\n scalar _FieldSet\n scalar link__Import\n\n enum link__Purpose {\n SECURITY\n EXECUTION\n }\n\n type _Service {\n sdl: String!\n }\n\n type Query {\n _service: _Service!\n }\n\n directive @external on FIELD_DEFINITION | OBJECT\n directive @requires(fields: _FieldSet!) on FIELD_DEFINITION\n directive @provides(fields: _FieldSet!) on FIELD_DEFINITION\n directive @key(fields: _FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE\n directive @link(\n url: String!\n as: String\n for: link__Purpose\n import: [link__Import]\n ) repeatable on SCHEMA\n directive @shareable repeatable on OBJECT | FIELD_DEFINITION\n directive @inaccessible on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION\n directive @tag(\n name: String!\n ) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION\n directive @override(from: String!) on FIELD_DEFINITION\n directive @composeDirective(name: String!) repeatable on SCHEMA\n\n directive @extends on OBJECT | INTERFACE\n"

Defined in

packages/federation/src/subgraph.ts:14


SubgraphSDLQuery

Const SubgraphSDLQuery: "\n query SubgraphSDL {\n _service {\n sdl\n }\n }\n"

Defined in

packages/federation/src/gateway.ts:31

Functions

buildSubgraphSchema

buildSubgraphSchema<TContext>(optsOrModules): GraphQLSchema

Type parameters

NameType
TContextany

Parameters

NameType
optsOrModulesIExecutableSchemaDefinition<TContext> | Pick<IExecutableSchemaDefinition<TContext>, "resolvers" | "typeDefs">[]

Returns

GraphQLSchema

Defined in

packages/federation/src/subgraph.ts:53


ensureSupergraphSDLAst

ensureSupergraphSDLAst(supergraphSdl): DocumentNode

Parameters

NameType
supergraphSdlstring | DocumentNode

Returns

DocumentNode

Defined in

packages/federation/src/supergraph.ts:68


federationSubschemaTransformer

federationSubschemaTransformer(subschemaConfig): SubschemaConfig<any, any, any, Record<string, any>> | SubschemaConfig<any, any, any, Record<string, any>>[]

Parameters

NameType
subschemaConfigSubschemaConfig<any, any, any, Record<string, any>>

Returns

SubschemaConfig<any, any, any, Record<string, any>> | SubschemaConfig<any, any, any, Record<string, any>>[]

Defined in

packages/federation/src/gateway.ts:221


fetchSupergraphSdlFromManagedFederation

fetchSupergraphSdlFromManagedFederation(options?): Promise<RouterConfig | Unchanged | FetchError>

Fetches the supergraph SDL from a managed federation GraphOS up link.

Parameters

NameType
optionsFetchSupergraphSdlFromManagedFederationOpts

Returns

Promise<RouterConfig | Unchanged | FetchError>

An object with the supergraph SDL when possible. It also includes metadata to handle polling and retry logic.

     If `lastSeenId` is provided and the supergraph has not changed, `supergraphSdl` is not present.

     If The up link report a fetch error (which is not a local fetch error), it will be returned along with polling/retry metadata.
     Any local fetch error will be thrown as an exception.

Throws

When the fetch fails or the response is not a valid.

Defined in

packages/federation/src/managed-federation.ts:132


filterInternalFieldsAndTypes

filterInternalFieldsAndTypes(finalSchema): GraphQLSchema

Parameters

NameType
finalSchemaGraphQLSchema

Returns

GraphQLSchema

Defined in

packages/federation/src/utils.ts:107


getArgsFromKeysForFederation

getArgsFromKeysForFederation(representations): Object

Parameters

NameType
representationsreadonly any[]

Returns

Object

NameType
representationsreadonly any[]

Defined in

packages/federation/src/utils.ts:4


getCacheKeyFnFromKey

getCacheKeyFnFromKey(key): (root: any) => any

Parameters

NameType
keystring

Returns

fn

▸ (root): any

Parameters
NameType
rootany
Returns

any

Defined in

packages/federation/src/utils.ts:86


getKeyFnForFederation

getKeyFnForFederation(typeName, keys): (root: any) => any

Parameters

NameType
typeNamestring
keysstring[]

Returns

fn

▸ (root): any

Parameters
NameType
rootany
Returns

any

Defined in

packages/federation/src/utils.ts:50


getKeyForFederation

getKeyForFederation<TRoot>(root): TRoot

Type parameters

Name
TRoot

Parameters

NameType
rootTRoot

Returns

TRoot

Defined in

packages/federation/src/utils.ts:8


getNamedTypeNode

getNamedTypeNode(typeNode): NamedTypeNode

Parameters

NameType
typeNodeTypeNode

Returns

NamedTypeNode

Defined in

packages/federation/src/utils.ts:158


getStitchedSchemaFromManagedFederation

getStitchedSchemaFromManagedFederation(options): Promise<RouterConfigWithSchema | FetchError | Unchanged>

Fetches the supergraph SDL from a managed federation GraphOS up link and stitches it into an executable schema.

Parameters

NameType
optionsGetStitchedSchemaFromManagedFederationOpts

Returns

Promise<RouterConfigWithSchema | FetchError | Unchanged>

An object with the supergraph SDL and the stitched schema when possible. It also includes metadata to handle polling and retry logic.

     If `lastSeenId` is provided and the supergraph has not changed, `supergraphSdl` is not present.

     If The up link report a fetch error (which is not a local fetch error), it will be returned along with polling/retry metadata.
     Any local fetch error will be thrown as an exception.

Throws

When the fetch fails, the response is not a valid or the stitching fails.

Defined in

packages/federation/src/managed-federation.ts:264


getStitchedSchemaFromSupergraphSdl

getStitchedSchemaFromSupergraphSdl(opts): GraphQLSchema

Parameters

NameType
optsGetStitchedSchemaFromSupergraphSdlOpts

Returns

GraphQLSchema

Defined in

packages/federation/src/supergraph.ts:1209


getStitchedSchemaWithUrls

getStitchedSchemaWithUrls(configs): Promise<GraphQLSchema>

Parameters

NameType
configsHTTPExecutorOptions[]

Returns

Promise<GraphQLSchema>

Defined in

packages/federation/src/gateway.ts:211


getStitchingOptionsFromSupergraphSdl

getStitchingOptionsFromSupergraphSdl(opts): Object

Parameters

NameType
optsGetStitchingOptionsFromSupergraphSdlOpts

Returns

Object

NameType
assumeValidboolean
assumeValidSDLboolean
subschemasSubschemaConfig<any, any, any, Record<string, any>>[]
typeDefsDocumentNode
typeMergingOptions{ fieldConfigMerger: (candidates: MergeFieldConfigCandidate<Record<string, any>>[]) => GraphQLFieldConfig<any, Record<string, any>, any> ; useNonNullableFieldOnConflict: boolean = true; validationSettings: { validationLevel: ValidationLevel = ValidationLevel.Off } }
typeMergingOptions.fieldConfigMerger(candidates: MergeFieldConfigCandidate<Record<string, any>>[]) => GraphQLFieldConfig<any, Record<string, any>, any>
typeMergingOptions.useNonNullableFieldOnConflictboolean
typeMergingOptions.validationSettings{ validationLevel: ValidationLevel = ValidationLevel.Off }
typeMergingOptions.validationSettings.validationLevelValidationLevel

Defined in

packages/federation/src/supergraph.ts:112


getSubschemaForFederationWithExecutor

getSubschemaForFederationWithExecutor(executor): Promise<{ batch?: boolean ; batchingOptions?: BatchingOptions<any, any, any> ; createProxyingResolver?: CreateProxyingResolverFn<Record<string, any>> ; executor: Executor ; merge?: Record<string, MergedTypeConfig<any, any, Record<string, any>>> ; name?: string ; rootValue?: any ; schema: GraphQLSchema ; transforms?: Transform<any, Record<string, any>>[] }>

Parameters

NameType
executorExecutor

Returns

Promise<{ batch?: boolean ; batchingOptions?: BatchingOptions<any, any, any> ; createProxyingResolver?: CreateProxyingResolverFn<Record<string, any>> ; executor: Executor ; merge?: Record<string, MergedTypeConfig<any, any, Record<string, any>>> ; name?: string ; rootValue?: any ; schema: GraphQLSchema ; transforms?: Transform<any, Record<string, any>>[] }>

Defined in

packages/federation/src/gateway.ts:182


getSubschemaForFederationWithSchema

getSubschemaForFederationWithSchema(schema): Promise<{ batch?: boolean ; batchingOptions?: BatchingOptions<any, any, any> ; createProxyingResolver?: CreateProxyingResolverFn<Record<string, any>> ; executor: Executor ; merge?: Record<string, MergedTypeConfig<any, any, Record<string, any>>> ; name?: string ; rootValue?: any ; schema: GraphQLSchema ; transforms?: Transform<any, Record<string, any>>[] }>

Parameters

NameType
schemaGraphQLSchema

Returns

Promise<{ batch?: boolean ; batchingOptions?: BatchingOptions<any, any, any> ; createProxyingResolver?: CreateProxyingResolverFn<Record<string, any>> ; executor: Executor ; merge?: Record<string, MergedTypeConfig<any, any, Record<string, any>>> ; name?: string ; rootValue?: any ; schema: GraphQLSchema ; transforms?: Transform<any, Record<string, any>>[] }>

Defined in

packages/federation/src/gateway.ts:206


getSubschemaForFederationWithTypeDefs

getSubschemaForFederationWithTypeDefs(typeDefs): SubschemaConfig

Parameters

NameType
typeDefsDocumentNode

Returns

SubschemaConfig

Defined in

packages/federation/src/gateway.ts:50


getSubschemaForFederationWithURL

getSubschemaForFederationWithURL(config): Promise<SubschemaConfig>

Parameters

NameType
configHTTPExecutorOptions

Returns

Promise<SubschemaConfig>

Defined in

packages/federation/src/gateway.ts:39


projectDataSelectionSet

projectDataSelectionSet(data, selectionSet?): any

Parameters

NameType
dataany
selectionSet?SelectionSetNode

Returns

any

Defined in

packages/federation/src/utils.ts:12