@graphql-mesh/fusion-composition
Version:
Basic composition utility for Fusion spec
154 lines (153 loc) • 6.98 kB
text/typescript
import { OperationTypeNode } from 'graphql';
import type { SubgraphTransform } from '../compose.cjs';
export interface FederationTransformConfig {
[schemaCoordinate: string]: FederationCoordinateConfig;
}
interface FederationCoordinateConfig {
/**
* Designates an object type as an entity and specifies its key fields.
* Key fields are a set of fields that a subgraph can use to uniquely identify any instance of the entity.
*
* [See Federation Spec](https://www.apollographql.com/docs/federation/federated-types/federated-directives/#key)
*/
key?: FederationKeyDirectiveConfig | FederationKeyDirectiveConfig[];
/**
* Indicates that an object definition serves as an abstraction of another subgraph's entity interface.
* This abstraction enables a subgraph to automatically contribute fields to all entities that implement a particular entity interface.
* During composition, the fields of every `@interfaceObject` are added both to their corresponding interface definition and to all entity types that implement that interface.
*
* [Learn more about entity interfaces.](https://www.apollographql.com/docs/federation/federated-types/interfaces)
*/
interfaceObject?: boolean;
/**
* Indicates that an object or interface definition is an extension of another definition of that same type.
*
* [See Federation spec](https://www.apollographql.com/docs/federation/federated-types/federated-directives/#extends)
*/
extends?: boolean;
/**
* Indicates that an object type's field is allowed to be resolved by multiple subgraphs (by default in Federation 2, object fields can be resolved by only one subgraph).
*
* [See Federation spec](https://www.apollographql.com/docs/federation/federated-types/federated-directives/#shareable)
*/
shareable?: boolean;
/**
* Indicates that a definition in the subgraph schema should be omitted from the router's API schema, even if that definition is also present in other subgraphs. This means that the field is not exposed to clients at all.
*
* [See Federation spec](https://www.apollographql.com/docs/federation/federated-types/federated-directives/#inaccessible)
*/
inaccessible?: boolean;
/**
* Indicates that an object field is now resolved by this subgraph instead of another subgraph where it's also defined. This enables you to migrate a field from one subgraph to another.
* You can apply @override to entity fields and fields of the root operation types (such as Query and Mutation).
*
* [See Federation spec](https://www.apollographql.com/docs/federation/federated-types/federated-directives/#override)
*/
override?: {
from: string;
};
authenticated?: boolean;
requiresScopes?: {
scopes: [[string]];
};
policy?: {
policies: [[string]];
};
/**
* Indicates that this subgraph usually can't resolve a particular object field, but it still needs to define that field for other purposes.
*
* [See Federation spec](https://www.apollographql.com/docs/federation/federated-types/federated-directives/#external)
*/
external?: boolean;
/**
* Specifies a set of entity fields that a subgraph can resolve, but only at a particular schema path (at other paths, the subgraph can't resolve those fields).
*
* [See Federation spec](https://www.apollographql.com/docs/federation/federated-types/federated-directives/#provides)
*/
provides?: {
fields: string;
};
/**
* Indicates that the resolver for a particular entity field depends on the values of other entity fields that are resolved by other subgraphs. This tells the router that it needs to fetch the values of those externally defined fields first, even if the original client query didn't request them.
*
* [See Federation spec](https://www.apollographql.com/docs/federation/federated-types/federated-directives/#requires)
*/
requires?: {
fields: string;
};
/**
* Applies arbitrary string metadata to a schema location. Custom tooling can use this metadata during any step of the schema delivery flow, including composition, static analysis, and documentation.
*
* [See Federation spec](https://www.apollographql.com/docs/federation/federated-types/federated-directives/#tag)
*/
tag?: {
name: string;
};
context?: {
name: string;
};
fromContext?: {
field?: string;
};
}
interface FederationKeyDirectiveConfig {
/**
* A list of fields that together uniquely identify an instance of the entity.
*
* @example `id`
*/
fields: string;
/**
* Define how to resolve the entity reference.
*/
resolveReference?: FederationResolveReferenceConfig;
}
interface FederationResolveReferenceConfig {
/**
* The operation to use to resolve the reference.
*
* @example MUTATION
* @default QUERY
*/
operation?: OperationTypeNode;
/**
* The field to use to resolve the reference.
*
* @example getBookById
*/
fieldName: string;
/**
* (WARNING: Advanced usage only)
* Specifies the name of a field to pick off origin objects as the key value.
* When omitted, a `@key` directive must be included on the return type’s definition to be built into an object key.
* As you already defined the key fields in the key directive, you can omit the keyField in here.
*/
keyField?: string;
/**
* Specifies which field argument receives the merge key.
* This may be omitted for fields with only one argument where the recipient can be inferred.
*
* @example bookId
*/
keyArg?: string;
/**
* Specifies a string of additional keys and values to apply to other arguments, formatted as `""" arg1: "value", arg2: "value" """`.
*/
additionalArgs?: string;
/**
* (WARNING: Advanced usage only)
* Allows building a custom key just for the argument from the `selectionSet` included by the `@key` directive.
*/
key?: string[];
/**
* (WARNING: Advanced usage only)
* This argument specifies a string expression that allows more customization of the input arguments.
* Rules for evaluation of this argument are as follows:
* - basic object parsing of the input key: `"arg1: $key.arg1, arg2: $key.arg2"`
* - any expression enclosed by double brackets will be evaluated once for each of the requested keys, and then sent as a list: `"input: { keys: [[$key]] }"`
* - selections from the key can be referenced by using the $ sign and dot notation: `"upcs: [[$key.upc]]"`, so that `$key.upc` refers to the upc field of the key.
*/
argsExpr?: string;
}
export declare function createFederationTransform(config: FederationTransformConfig): SubgraphTransform;
export {};