@graphql-tools/delegate
12.3.4 · 12 Nov 2026MIT15.8M / weekRepositorynpmAtom feed
219 stable releases, newest first, by release line. Notes are quoted as the maintainers published them.
- 10.x
10.2.12
13 Feb 2025Dependencies updates:
Patch Changes
Dependencies updates:
Updated dependency
@graphql-tools/utils@^10.8.1↗︎ (from^10.7.0, independencies)
10.2.11
29 Jan 2025- Security
Add
isPrototypePollutingKeyto prevent accidential prototype pollution, whenever object manipulation happens with the keys based on the user input, it is validated to prevent prototype pollution.For example,
WrapQuerytakespathwhich is used to manipulate the object returned to the client. If the user input is__proto__, it will throw an error from now on but previously it would have polluted the prototype.
10.2.10
20 Jan 2025While creating a delegation request for the subschema, an selection set should be spreaded on the union type field correctly.
In case of the following schema;
type Query { foo: Foo } union Foo = Bar | Baz type Bar { id: ID! name: String age: Age } type Age { years: Int months: Int } type Baz { id: ID! name: Name age: Int } type Name { first: String last: String }If the operation is generated as following;
query { foo { id name age { years months } } }It should be spreaded on the union type field correctly as following;
query { foo { ... on Bar { id age { years months } } ... on Baz { id name { first last } } } }
10.2.9
24 Dec 2024Dependencies updates:
Patch Changes
Dependencies updates:
Updated dependency
@graphql-tools/executor@^1.3.10↗︎ (from^1.3.8, independencies)Updated dependency
@graphql-tools/utils@^10.7.0↗︎ (from^10.6.2, independencies)
10.2.8
13 Dec 2024Dependencies updates:
10.2.7
6 Dec 2024Dependencies updates:
Patch Changes
Dependencies updates:
Updated dependency
tslib@^2.8.1↗︎ (from^2.5.0, independencies)
10.2.6
4 Dec 2024Dependencies updates:
Dependencies updates:
Patch Changes
Dependencies updates:
Updated dependency
dataloader@^2.2.3↗︎ (from^2.2.2, independencies)
Dependencies updates:
Updated dependency
@graphql-tools/executor@^1.3.6↗︎ (from^1.3.3, independencies)Updated dependency
@graphql-tools/schema@^10.0.11↗︎ (from^10.0.8, independencies)Updated dependency
@graphql-tools/utils@^10.6.2↗︎ (from^10.6.0, independencies)
10.2.5
3 Dec 2024Do not show internal non-nullability errors in the gateway
10.2.4
2 Dec 2024Only updates a dependency:@graphql-tools/batch-execute 9.0.8
10.2.3
2 Dec 2024Avoid extensions and use `stitchingInfo` for provided fields
10.2.2
29 Nov 2024Fix missing key fields in the nested queries
10.2.1
27 Nov 2024Dependencies updates:
Patch Changes
Dependencies updates:
Updated dependency
@graphql-tools/utils@^10.6.0↗︎ (from^10.5.6, independencies)
10.2.0
20 Nov 2024Introduce `onDelegationPlan` and `onDelegationStageExecuteDone` hooks
10.1.3
19 Nov 2024Thanks @{! - Do not ignore request selection set when overriding the fields
import { buildSchema, graphql } from 'graphql'; import { addResolversToSchema } from '@graphql-tools/schema'; import { stitchSchemas } from '@graphql-tools/stitch'; import { delegateToSchema } from '@graphql-tools/delegate'; const sub_schema = addResolversToSchema({ schema: buildSchema(` type Query { current_user: User } type User { id: ID! name: String! age: Int! } `), resolvers: { Query: { current_user: () => ({ id: '5', name: 'John Doe', age: 10 }), }, }, }); const stitched_schema = stitchSchemas({ subschemas: [ { schema: sub_schema, createProxyingResolver: (options) => { return (_parent, _args, context, info) => { const operationName = info.operation.name ? info.operation.name.value : undefined; return delegateToSchema({ schema: options.subschemaConfig, operation: options.operation, context, info, operationName, }); }; }, }, ], resolvers: { name: { selectionSet: '{ age }', resolve: (parent) => `${parent.name}(${parent.age})`, // Age should be here }, }, }, });
10.0.23
16 Oct 2024#6573
7e2938dThanks @ardatan! - When there are two services like below then the following query senty, the gateway tries to fetchidas an extra field because it considersidmight be needed while this is not correct. This patch avoids any extra calls, and forwards the query as is to the 2nd service.query { viewer { booksContainer(input: $input) { edges { cursor node { source { # Book(upc=) upc } } } pageInfo { endCursor } } } }type Book @key(fields: "id") @key(fields: "upc") { id: ID! upc: ID! }type BookContainer { # the type that is used in a collection id: ID! # ... other stuff here source: Book! } type Book @key(fields: "upc") { upc: ID! } type Query { viewer: Viewer } type Viewer { booksContainer: BooksContainerResult } type BooksContainerResult { edges: [BooksContainerEdge!]! pageInfo: PageInfo! } type BooksContainerEdge { node: BookContainer! cursor: String! } type PageInfo { endCursor: String }
10.0.22
15 Oct 202410.0.20
26 Aug 2024#6469
0e87805Thanks @User!! - Handle merged selection sets in the computed fields;When a selection set for a computed field needs to be merged, resolve that required selection set fully then resolve the computed field. In the following case, the selection set for the
authorfield in thePosttype is merged with the selection set for theauthorIdfield in theCommenttype.type Query { feed: [Post!]! } type Post { id: ID! @computed(selectionSet: "{ comments { authorId } }") } type Comment { id: ID! authorId: ID! } type User { id: ID! name: String! }type Post { id: ID! comments: [Comment!]! } type Comment { id: ID! }
10.0.19
14 Aug 2024#6437
3188051Thanks @User, @(), @{, @{, @{, @{, @{! - Fix the bug happens when a merged field is a computed field requires another computed field requires a field from the initial subschema.In the following test case,
totalOrdersPricesneedsuserOrderswhich needslastNamefrom initialQuery.user. So the bug was skipping the dependencies ofuserOrdersbecause it assumedlastNamealready there by mistake.const schema1 = makeExecutableSchema({ typeDefs: /* GraphQL */ ` type User { id: ID! firstName: String! lastName: String! address: String } type Query { } `, resolvers: { Query: { => { return { id: 1, firstName: 'Jake', lastName: 'Dawkins', address: 'everywhere', }; }, }, }, }); const schema2 = makeExecutableSchema({ typeDefs: /* GraphQL */ ` type UserOrder { id: ID! } type User { id: ID! totalOrdersPrices: Int aggregatedOrdersByStatus: Int } type Query { userWithOrderDetails(userId: ID!, userOrderIds: [ID]): User } `, resolvers: { Query: { userWithOrderDetails: (_root, { userId, userOrderIds }) => { return { id: userId, userOrders: userOrderIds?.map((userOrderId: string) => ({ id: userOrderId })), }; }, }, totalOrdersPrices(user) { if (user.userOrders instanceof Error) { return user.userOrders; } if (!user.userOrders) { throw new Error('UserOrders is required'); } return 0; }, aggregatedOrdersByStatus(user) { if (user.userOrders instanceof Error) { return user.userOrders; } if (!user.userOrders) { throw new Error('UserOrders is required'); } return 1; }, }, }, }); const schema3 = makeExecutableSchema({ typeDefs: /* GraphQL */ ` type User { id: ID! userOrders: [UserOrder!] } type UserOrder { id: ID! } type Query { userWithOrders(id: ID!, lastName: String): User } `, resolvers: { Query: { userWithOrders: (_root, { id, lastName }) => { return { id, lastName, }; }, }, userOrders(user) { if (!user.lastName) { throw new Error('LastName is required'); } return [ { id: `${user.lastName}1`, }, ]; }, }, }, }); const stitchedSchema = stitchSchemas({ subschemas: [ { schema: schema1, }, { schema: schema2, merge: { selectionSet: '{ id }', fieldName: 'userWithOrderDetails', args: ({ id, userOrders }: { id: string; userOrders: any[] }) => ({ userId: id, userOrderIds: userOrders?.map?.(({ id }: { id: string }) => id), }), fields: { totalOrdersPrices: { selectionSet: '{ userOrders { id } }', computed: true, }, aggregatedOrdersByStatus: { selectionSet: '{ userOrders { id } }', computed: true, }, }, }, }, }, { schema: schema3, merge: { selectionSet: '{ id }', fieldName: 'userWithOrders', args: ({ id, lastName }: { id: string; lastName: string }) => ({ id, lastName, }), fields: { userOrders: { selectionSet: '{ lastName }', computed: true, }, }, }, }, }, ], }); const res = await normalizedExecutor({ schema: stitchedSchema, document: parse(/* GraphQL */ ` query User { user { aggregatedOrdersByStatus totalOrdersPrices } } `), }); expect(res).toEqual({ data: { aggregatedOrdersByStatus: 1, totalOrdersPrices: 0, }, }, });
10.0.18
7 Aug 2024#6418
da93c08Thanks @ardatan! - Fix extra inline fragments for all abstract types in the upstream schema callIf there are two subschemas like below, the final
Nodeinterface is implemented by bothOvenandToasterwhile they are not implemented in both schemas. In this case the query{ products { id ... on Node { id } } }will need to be transformed to{ products { id ... on Oven { id } ... on Node { id } } }for the first subschema. But previously the query planner was automatically creating inline fragments for all possible types which was not optimal. Now it adds inline fragments only if this case is seen.type Query { products: [Product] } union Product = Oven | Toaster interface Node { id: ID! } type Oven { id: ID! } type Toaster implements Node { id: ID! warranty: Int }And another one like below;
interface Node { id: ID! } type Oven implements Node { id: ID! warranty: Int }
Patch Changes
#6420
a867bbcThanks @ardatan! - dependencies updates:Added dependency
@repeaterjs/repeater@^3.0.6↗︎ (todependencies)
#6420
a867bbcThanks @ardatan! - Pass operation directives correctly to the subschema;query { hello @someDir }#6418
da93c08Thanks @ardatan! - Fix extra inline fragments for all abstract types in the upstream schema callIf there are two subschemas like below, the final
Nodeinterface is implemented by bothOvenandToasterwhile they are not implemented in both schemas. In this case the query{ products { id ... on Node { id } } }will need to be transformed to{ products { id ... on Oven { id } ... on Node { id } } }for the first subschema. But previously the query planner was automatically creating inline fragments for all possible types which was not optimal. Now it adds inline fragments only if this case is seen.type Query { products: [Product] } union Product = Oven | Toaster interface Node { id: ID! } type Oven { id: ID! } type Toaster implements Node { id: ID! warranty: Int }And another one like below;
interface Node { id: ID! } type Oven implements Node { id: ID! warranty: Int }
10.0.15 – 10.0.162 releases with no change for you1 dependency update, 1 without a note@graphql-tools/executor 1.3.0Show each
- 10.0.1623 Jul 2024@graphql-tools/executor 1.3.0
- 10.0.1522 Jul 2024no note
10.0.14
18 Jul 2024#6356
8094c37Thanks @enisdenjo! - AggregateError errors are GraphQL located errorsInstead of transforming the AggregateError itself to a GraphQL located error.
This is because of two reasons:
10.0.11
27 May 2024Patch Changes
#6194
7368829Thanks @ardatan! - Handle interface objects in a different way#6188
e10c13aThanks @ardatan! - AddsubtractSelectionSetsto get the diff of two selection sets#6187
dfccfbfThanks @ardatan! - Do not merge errors and regular resolved objectsIf a subschema returns an error for specific field that is already resolved by another subschema, the error should not be merged with the resolved object.
#6189
0134f7fThanks @ardatan! - Handle interface types with non-shared implementations;For example, you have the following services, where
Nodeis implemented in both services, butFooandBarare only implemented in one service. And when the gateway receives the following query, it should be converted to this becauseNodeis not implemented asBarin Service 1 while implemented in Service 2.Query conversion;
# Gateway request query { fooBar(id: "1") { ... on Node { id } } }# Service 1 Request query { fooBar(id: "1") { ... on Foo { id } ... on Bar { id } } }Services;
# Service 1 union FooBar = Foo | Bar interface Node { id: ID! } type Foo implements Node { id: ID! } type Bar { id: ID! } type Query { fooBar(id: ID!): FooBar }# Service 2 interface Node { id: ID! } type Foo implements Node { id: ID! } type Bar implements Node { id: ID! }
10.0.10
8 May 2024- Breaking
#4566
d8dc67aaThanks @ardatan! - ## Breaking changesSchema generation optimization by removing
transfomedSchemaparameterPreviously we were applying the transforms multiple times. We needed to introduced some breaking changes to improve the initial wrapped/stitched schema generation performance;
stitchSchemasdoesn't take nested arrays of subschemasstitchSchemasno longer accepts an array of arrays of subschema configuration objects. Instead, it accepts an array of subschema configuration objects or schema objects directly.stitchSchemasno longer prunes the schema withpruningOptionsYou can use
pruneSchemafrom@graphql-tools/utilsto prune the schema instead.stitchSchemasno longer respect "@computed" directive if stitchingDirectivesTransformer isn't appliedAlso
@graphql-tools/stitchno longer exportscomputedDirectiveTransformeranddefaultSubschemaConfigTransforms. Instead, use@graphql-tools/stitching-directivespackage for@computeddirective. Learn more about setting it upcomputedFieldshas been removed from the merged type configurationMergeTypeConfig.computedFieldssetting has been removed in favor of new computed field configuration written as:merge: { MyType: { fields: { myComputedField: { selectionSet: '{ weight }', computed: true, } } } }A field-level
selectionSetspecifies field dependencies while thecomputedsetting structures the field in a way that assures it is always selected with this data provided. TheselectionSetis intentionally generic to support possible future uses. This new pattern organizes all field-level configuration (includingcanonical) into a single structure. - Breaking
BREAKING CHANGE
Patch Changes
#6134
a83da08Thanks @User! - Ignore unmerged fieldsLet's say you have a gateway schema like in the bottom, and
idis added to the query, only if theageis requested;# This will be sent as-is { user { name } }But the following will be transformed;
{ user { name age } }Into
{ user { id name age } } ```graphql type Query { } type User { id: ID! # is the key for all services name: String! age: Int! # This comes from another service }#6150
fc9c71fThanks @ardatan! - If there are some fields depending on a nested type resolution, wait until it gets resolved then resolve the rest.See packages/federation/test/fixtures/complex-entity-call example for more details. You can see
ProductListneeds some fields fromProductto resolvefirst
Patch Changes
#6126
680351eThanks @ardatan! - When there is a Node subschema, and others to resolve the rest of the entities by using a union resolver as in Federation like below, it was failing. This version fixes that issue.query { node(id: "1") { id # Fetches from Node ... on User { name # Fetches from User } } }type Query { node(id: ID!): Node } interface Node { id: ID! } type User implements Node { id: ID! } type Post implements Node { id: ID! }# User subschema scalar _Any type Query { _entities(representations: [_Any!]!): [_Entity]! } union _Entity = User interface Node { id: ID! } type User implements Node { id: ID! name: String! }# Post subschema scalar _Any union _Entity = Post type Query { _entities(representations: [_Any!]!): [_Entity]! } interface Node { id: ID! } type Post implements Node { id: ID! title: String! }
Patch Changes
Patch Changes
Patch Changes
af7be09Thanks @ardatan! - Hotfix: do not use nullable and nonNullable prefixes if field names don't match
Patch Changes
#6091
9bca9e0Thanks @User, @User! - If the gateway receives a query with an overlapping fields for the subschema, it uses aliases to resolve it correctly.Let's say subschema A has the following schema;
type Query { } interface User { id: ID! name: String! } type Admin implements User { id: ID! name: String! role: String! } type Customer implements User { id: ID! name: String email: String }And let's say the gateway has the following schema instead;
type Query { } interface User { id: ID! name: String! } type Admin implements User { id: ID! name: String! role: String! } type Customer implements User { id: ID! name: String! email: String! }In this case, the following query is fine for the gateway but for the subschema, it's not;
query { user { ... on Admin { id name # This is nullable in the subschema role } ... on Customer { id name # This is non-nullable in the subschema email } } }So the subgraph will throw based on this rule OverlappingFieldsCanBeMerged
To avoid this, the gateway will use aliases to resolve the query correctly. The query will be transformed to the following;
query { user { ... on Admin { id name # This is nullable in the subschema role } ... on Customer { id name: _nullable_name # This is non-nullable in the subschema email } } }#6092
243c353Thanks @ardatan! - If one of the subgraphs are already able to resolve a nested field as inparent-entity-callexample'sCategory.detailsfrom C'sProduct, resolve it from there instead of using type merging.query { product { category { details { # This is coming from C's Product, so resolve it from there instead of Type Merging id name } } } }
Patch Changes
#5913
83c0af0Thanks @enisdenjo! - dependencies updates:Updated dependency
@graphql-tools/schema@^10.0.2↗︎ (from^10.0.0, independencies)Updated dependency
@graphql-tools/utils@^10.0.13↗︎ (from^10.0.5, independencies)
#5913
83c0af0Thanks @enisdenjo! - No unnecessary inline fragment spreads for union types
Patch Changes
Patch Changes
#5477
cfd47827Thanks @ardatan! - dependencies updates:Removed dependency
value-or-promise@^1.0.12↗︎ (fromdependencies)
a59fb765Thanks @ardatan! - Optimizations to get better performance in query planning
Patch Changes
Major Changes
Patch Changes
Patch Changes
Patch Changes
Patch Changes
#5131
f26392a6Thanks @neumark! - Create symbols with Symbol.for() because multiple copies of delegate cause stitching bugs otherwise.
Patch Changes
#5067
492220cbThanks @n1ru4l! - dependencies updates:Updated dependency
@graphql-tools/batch-execute@^8.5.18↗︎ (from8.5.18, independencies)Updated dependency
@graphql-tools/executor@^0.0.14↗︎ (from0.0.14, independencies)Updated dependency
@graphql-tools/schema@^9.0.16↗︎ (from9.0.16, independencies)Updated dependency
@graphql-tools/utils@^9.2.1↗︎ (from9.2.1, independencies)Updated dependency
dataloader@^2.2.2↗︎ (from2.2.2, independencies)Updated dependency
tslib@^2.5.0↗︎ (from~2.5.0, independencies)Updated dependency
value-or-promise@^1.0.12↗︎ (from1.0.12, independencies)
Patch Changes
#5055
30bd4d0cThanks @renovate! - dependencies updates:Updated dependency
dataloader@2.2.2↗︎ (from2.2.1, independencies)
Patch Changes
#5025
b09ea282Thanks @renovate! - dependencies updates:Updated dependency
dataloader@2.2.1↗︎ (from2.1.0, independencies)
Patch Changes
#4995
772b948aThanks @renovate! - dependencies updates:Updated dependency
tslib@~2.5.0↗︎ (from~2.4.0, independencies)
Patch Changes
#4943
a4d36fccThanks @renovate! - dependencies updates:Updated dependency
value-or-promise@1.0.12↗︎ (from1.0.11, independencies)
Patch Changes
Patch Changes
#4890
eb6cd8b6Thanks @ardatan! - Transform provided argument values properly#4890
eb6cd8b6Thanks @ardatan! - Handle argument definitions correctly during delegation and transformations
Patch Changes
Patch Changes
13c24883Thanks @ardatan! - Fix handling argument values in gateway requestb5e6459fThanks @ardatan! - Show warning only if DEBUG env var is present
Patch Changes
Patch Changes
#4778
df5848b8Thanks @saihaj! - dependencies updates:Added dependency
@graphql-tools/executor@0.0.0↗︎ (todependencies)
Patch Changes
Patch Changes
00c4a1a4Thanks @ardatan! - If type is a list but the provided value isn't, do not fail and resolve that value as the member of that list type
Patch Changes
Patch Changes
Major Changes
- Breaking
#4566
d8dc67aaThanks @ardatan! - ## Breaking changesSchema generation optimization by removing
transfomedSchemaparameterPreviously we were applying the transforms multiple times. We needed to introduced some breaking changes to improve the initial wrapped/stitched schema generation performance;
Transform.transformSchemano longer acceptstransformedSchemawhich can easily be created withapplySchemaTransforms(schema, subschemaConfig)instead.Proxying resolver factory function that is passed as
createProxyingResolvertoSubschemaConfigno longer takestransformedSchemawhich can easily be created withapplySchemaTransforms(schema, subschemaConfig)instead.
stitchSchemasdoesn't take nested arrays of subschemasstitchSchemasno longer accepts an array of arrays of subschema configuration objects. Instead, it accepts an array of subschema configuration objects or schema objects directly.stitchSchemasno longer prunes the schema withpruningOptionsYou can use
pruneSchemafrom@graphql-tools/utilsto prune the schema instead.stitchSchemasno longer respect "@computed" directive if stitchingDirectivesTransformer isn't appliedAlso
@graphql-tools/stitchno longer exportscomputedDirectiveTransformeranddefaultSubschemaConfigTransforms. Instead, use@graphql-tools/stitching-directivespackage for@computeddirective. Learn more about setting it upcomputedFieldshas been removed from the merged type configurationMergeTypeConfig.computedFieldssetting has been removed in favor of new computed field configuration written as:merge: { MyType: { fields: { myComputedField: { selectionSet: '{ weight }', computed: true, } } } }A field-level
selectionSetspecifies field dependencies while thecomputedsetting structures the field in a way that assures it is always selected with this data provided. TheselectionSetis intentionally generic to support possible future uses. This new pattern organizes all field-level configuration (includingcanonical) into a single structure.
Patch Changes
#4624
e3167edcThanks @n1ru4l! - Fix CommonJS TypeScript resolution withmoduleResolutionnode16ornodenext
Minor Changes
Support TypeScript module resolution.
Patch Changes
Remove graphql-executor to have smaller bundle size
Patch Changes
Use caret range for the tslib dependency
Patch Changes
Relax subschema error path check
...as (apparently) some implementations may return path as
nullrather than not returning a path.
Patch Changes
Refine generic typings using
extends Xwhen appropriateTypescript 4.7 has stricter requirements around generics which is explained well in the related PR: #48366
These changes resolve the errors that these packages will face when attempting to upgrade to TS 4.7 (still in beta at the time of writing this). Landing these changes now will allow other TS libraries which depend on these packages to experiment with TS 4.7 in the meantime.
Patch Changes
Bump data-loader and cross-undici-fetch
Minor Changes
enhance(delegate): use graphql-executor for subscriptions
Minor Changes
Forward gateway operation's name to subschema executors
Patch Changes
Fix - align versions
Patch Changes
enhance(delegate): type is now inferred from the transformed subschema instead of unified schema
enhance(stitch): support promises in key functions
Patch Changes
delegate: Do not resolve the type twice
Patch Changes
visitResult: Ignore if field not present in visited object
Minor Changes
Add better type support for stitchSchemas using subschema transformations
Patch Changes
enhance: Avoid using globalThis
Patch Changes
isAsyncIterable should check if it is an object with iterator factory function
Patch Changes
enhance: Use ^ for tslib dependency
Minor Changes
enhance: Make operationType optional
Minor Changes
Getting ready for GraphQL v16
Patch Changes
enhance: Show more clear error messages for aggregated error
Patch Changes
batch-execute enhancements:
fixes bugs with batched fragment definitions
unpathed errors are now returned for all batch results
the "graphqlTools" prefix is simplified down to just "_"
new tests and documentation
Patch Changes
delegate: Pass an empty array if fieldNodes is falsy
Minor Changes
enhance(utils): copy inspect util from graphql-js
GraphQL v16 support
enhance(utils): move memoize functions to utils
enhance(utils): copy collectFields from graphql-js@16 for backwards compat
Patch Changes
enhance: Remove TypeMap and small improvements
Patch Changes
Use version ranges instead of a fixed version for the graphql-tools package versions
Patch Changes
Fix nested type merges with repeated children ignore all but first occurrence
Patch Changes
delegate: Visit list values to collect variables
Patch Changes
delegate: Collect variables from directives on FragmentSpread
Patch Changes
delegate: Handle variables correctly
Patch Changes
delegate: Ignore if stitchingInfo is not in extensions
Patch Changes
delegate: Fix ESM import
Major Changes
- Breaking
BREAKING CHANGE
Remove
rootValuefrom subschemaConfigPass it through
ExecutionParamsor delegation optionsDo not pass
info.rootValueifrootValueis falsy
- Breaking
BREAKING CHANGES;
Refactor the core delegation transforms into individual functions to modify request and results. This will improve the performance considerably by reducing the number of visits over the request document.
Replace
CheckResultAndHandleErrorswithcheckResultAndHandleErrorsRemove
delegationBindingsReplace
AddArgumentsAsVariables,AddSelectionSets,AddTypenameToAbstract,ExpandAbstractTypes,FilterToSchema,VisitSelectionSetsandWrapConcreteTypeswithprepareGatewayDocumentandfinalizeGatewayRequest
- Breaking
ExecutionParams type replaced by Request type
rootValue property is now a part of the Request type.
When delegating with delegateToSchema, rootValue can be set multiple ways:
when using a custom executor, the custom executor can utilize a rootValue in whichever custom way it specifies.
when using the default executor (execute/subscribe from graphql-js): -- rootValue can be passed to delegateToSchema via a named option -- rootValue can be included within a subschemaConfig -- otherwise, rootValue is inferred from the originating schema
When using wrapSchema/stitchSchemas, a subschemaConfig can specify the createProxyingResolver function which can pass whatever rootValue it wants to delegateToSchema as above.
- Breaking
BREAKING CHANGES;
Rename
RequesttoExecutionRequestAdd required
operationType: OperationTypeNodefield inExecutionRequestAdd
contextincreateRequestandcreateRequestInfoinstead ofdelegateToSchema
It doesn't rely on info.operation.operationType to allow the user to call an operation from different root type. And it doesn't call getOperationAST again and again to get operation type from the document/operation because we have it in Request and ExecutionParams #3166
Improvements;
Memoize
defaultExecutorfor a singleGraphQLSchemaso allowgetBatchingExecutorto memoizebatchingExecutorcorrectly.And there is no different
defaultExecutoris created forsubscriptionand other operation types. Only one executor is used.
Batch executor is memoized by
executorreference butcreateDefaultExecutordidn't memoize the default executor so this memoization wasn't working correctly onbatch-executeside. github.com/ardatan/graphql-tools/blob/remove-in… - Breaking
BREAKING CHANGE
Now it uses the native
AggregateErrorimplementation. The major difference is the individual errors are kept undererrorsproperty instead of the object itself withSymbol.iterator.
// From; for (const error of aggregateError) // To; for (const error of aggregateError.errors)
- Breaking
Validations are skipped by default, use validateRequest: true to reenable
- Breaking
BREAKING CHANGE
Remove Subscriber and use only Executor
Now
Executorcan receiveAsyncIterableand subscriptions will also be handled byExecutor. This is a future-proof change for defer, stream and live queries
Patch Changes
Use value-or-promise to streamline working with sync values or async promises
Patch Changes
delegate: Handle executor errors
Patch Changes
Allows
MergedTypeConfigto be written with anentryPointsarray for multiple merged type entry points, each with their ownfieldNameandselectionSet:{ schema: testSchema, merge: { Product: { entryPoints: [{ selectionSet: '{ id }', fieldName: 'productById', key: ({ id, price, weight }) => ({ id, price, weight }), argsFromKeys: (key) => ({ key }), }, { selectionSet: '{ upc }', fieldName: 'productByUpc', key: ({ upc, price, weight }) => ({ upc, price, weight }), argsFromKeys: (key) => ({ key }), }], } } }These multiple entry points accommodate types with multiple keys across services that rely on a central service to join them, for example:
Catalog service:
type Product { upc }Vendors service:
type Product { upc id }Reviews service:
type Product { id }
Given this graph, the possible traversals require the Vendors service to provide entry points for each unique key format:
Catalog > Vendors > ReviewsCatalog < Vendors > ReviewsCatalog < Vendors < Reviews
Is it highly recommended that you enable query batching for subschemas with multiple entry points.
Patch Changes
- Breaking
delegate: Export executor typings not to have breaking change
Minor Changes
types: Add TContext to stitchSchemas and executor
Patch Changes
- Deprecated
Deprecates the
MergeTypeConfig.computedFieldssetting (with backwards-compatible warning) in favor of new computed field configuration written as:merge: { MyType: { fields: { myComputedField: { selectionSet: '{ weight }', computed: true, } } } }A field-level
selectionSetspecifies field dependencies while thecomputedsetting structures the field in a way that assures it is always selected with this data provided. TheselectionSetis intentionally generic to support possible future uses. This new pattern organizes all field-level configuration (includingcanonical) into a single structure.
Patch Changes
fix(delegate) fix array check
enhance(stitch) canonical merged type and field definitions. Use the @canonical directive to promote preferred type and field descriptions into the combined gateway schema.
Patch Changes
stitch: Type merging for nested root types
Because root types do not usually require selectionSets, a nested root type proxied to a remote service may end up having an empty selectionSet, if the nested root types only includes fields from a different subservice.
Empty selection sets return null, but, in this case, it should return an empty object. We can force this behavior by including the __typename field which exists on every schema.
Addresses #2347.
In the future, we may want to include short-circuiting behavior that when delegating to composite fields, if an empty selection set is included, an empty object is returned rather than null. This short-circuiting behavior would be complex for lists, as it would be unclear the length of the list...
delegate: Resolve external values only once
Because items in a list may be identical and the defaultMergedResolver mutates those objects when resolving them as external values, a check is required so that the mutation happens only once.
Partially addresses #2304
Patch Changes
typeMerging: Enable subschemas to use keys that have been renamed via transforms
batch-delegate: Proxy batched errors
Patch Changes
delegate: Add selectionSets prior to expanding abstract types
Patch Changes
enhance(stitch): custom merge resolvers
Patch Changes
delegate: Import AggregateError polyfill
Patch Changes
delegate: WrapConcreteTypes should not process fragments that are not on a root type (#2173)
Patch Changes
stitch: Fix mergeExternalObject regressions
v7 introduced a regression in the merging of ExternalObjects that causes type merging to fail when undergoing multiple rounds of merging.
Patch Changes
delegate: Fix type error with
argumentsbeing undefined
Major Changes
- Breaking
Breaking Changes:
Schema Generation and Decoration API (
@graphql-tools/schema)- Breaking
Resolver validation options should now be set to
error,warnorignorerather thantrueorfalse. In previous versions, some of the validators caused errors to be thrown, while some issued warnings. This changes brings consistency to validator behavior. - Breaking
The
allowResolversNotInSchemahas been renamed torequireResolversToMatchSchema, to harmonize the naming convention of all the validators. The default setting ofrequireResolversToMatchSchemaiserror, matching the previous behavior.
Schema Delegation (
delegateToSchema&@graphql-tools/delegate)- Breaking
The
delegateToSchemareturn value has matured and been formalized as anExternalObject, in which all errors are integrated into the GraphQL response, preserving their initial path. Those advanced users accessing the result directly will note the change in error handling. This also allows for the deprecation of unnecessary helper functions includingslicedError,getErrors,getErrorsByPathSegmentfunctions. Only external errors with missing or invalid paths must still be preserved by annotating the remote object with special properties. The newgetUnpathedErrorsfunction is therefore necessary for retrieving only these errors. Note also the newannotateExternalObjectandmergeExternalObjectsfunctions, as well as the renaming ofhandleResulttoresolveExternalValue. - Breaking
Transform types and the
applySchemaTransformsare now relocated to thedelegatepackage;applyRequestTransforms/applyResultTransformsfunctions have been deprecated, however, as this functionality has been replaced since v6 by theTransformerabstraction. - Breaking
The
transformRequest/transformResultmethods are now provided additionaldelegationContextandtransformationContextarguments -- these were introduced in v6, but previously optional. - Breaking
The
transformSchemamethod may wish to create additional delegating resolvers and so it is now provided thesubschemaConfigand final (non-executable)transformedSchemaparameters. As in v6, thetransformSchemais kicked off once to produce the non-executable version, and then, if a wrapping schema is being generated, proxying resolvers are created with access to the (non-executable) initial result. In v7, the individualtransformSchemamethods also get access to the result of the first run, if necessary, they can create additional wrapping schema proxying resolvers. - Breaking
applySchemaTransformsparameters have been updated to match and support thetransformSchemaparameters above.
Remote Schemas & Wrapping (
wrapSchema,makeRemoteExecutableSchema, and@graphql-tools/wrap)- Breaking
wrapSchemaandgenerateProxyingResolversnow only take a single options argument with named properties of typeSubschemaConfig. The previously possible shorthand version with first argument consisting of aGraphQLSchemaand second argument representing the transforms should be reworked as aSubschemaConfigobject. - Breaking
Similarly, the
ICreateProxyingResolverOptionsinterface that provides the options for thecreateProxyingResolverproperty ofSubschemaConfigoptions has been adjusted. Theschemaproperty previously could be set to aGraphQLSchemaor aSubschemaConfigobject. This property has been removed in favor of asubschemaConfigproperty that will always be aSubschemaConfigobject. Thetransformsproperty has been removed; transforms should be included within theSubschemaConfigobject.` - Breaking
The format of the wrapping schema has solidified. All non-root fields are expected to use identical resolvers, either
defaultMergedResolveror a custom equivalent, with root fields doing the hard work of proxying. Support for custom merged resolvers throughtcreateMergedResolverhas been deprecated, as custom merging resolvers conflicts when using stitching's type merging, where resolvers are expected to be identical across subschemas. - Breaking
The
WrapFieldstransform'swrappingResolveroption has been removed, as this complicates multiple wrapping layers, as well as planned functionality to wrap subscription root fields in potentially multiple layers, as the wrapping resolvers may be different in different layers. Modifying resolvers can still be performed by use of an additional transform such asTransformRootFieldsorTransformObjectFields. - Breaking
The
ExtendSchematransform has been removed, as it is conceptually simpler just to usestitchSchemaswith one subschema. - Breaking
The
ReplaceFieldsWithFragment,AddFragmentsByField,AddSelectionSetsByField, andAddMergedTypeSelectionSetstransforms has been removed, as they are superseded by theAddSelectionSetsandVisitSelectionSetstransforms. TheAddSelectionSetspurposely takes parsed SDL rather than strings, to nudge end users to parse these strings at build time (when possible), rather than at runtime. Parsing of selection set strings can be performed using theparseSelectionSetfunction from@graphql-tools/utils.
Schema Stitching (
stitchSchemas&@graphql-tools/stitch)- Breaking
stitchSchemas'smergeTypesoption is now true by default! This causes theonTypeConflictoption to be ignored by default. To useonTypeConflictto select a specific type instead of simply merging, simply setmergeTypesto false. - Breaking
schemasargument has been deprecated, usesubschemas,typeDefs, ortypes, depending on what you are stitching. - Breaking
When using batch delegation in type merging, the
argsFromKeysfunction is now set only via theargsFromKeysproperty. Previously, ifargsFromKeyswas absent, it could be read fromargs. - Breaking
Support for fragment hints has been removed in favor of selection set hints.
- Breaking
stitchSchemasnow processes allGraphQLSchemaandSubschemaConfigsubschema input into newSubschemaobjects, handling schema config directives such aso@computedas well as generating the final transformed schema, stored as thetransformedSchemaproperty, if transforms are used. Signatures of theonTypeConflict,fieldConfigMerger, andinputFieldConfigMergerhave been updated to include metadata related to the original and transformed subschemas. Note the property name change foronTypeConflictfromschematosubschema.
Mocking (
addMocksToSchemaand@graphql-tools/mock)- Breaking
Mocks returning objects with fields set as functions are now operating according to upstream graphql-js convention, i.e. these functions take three arguments,
args,context, andinfowithparentavailable asthisrather than as the first argument.
Other Utilities (
@graphql-tools/utils)- Breaking
filterSchema'sfieldFilterwill now filter all fields across Object, Interface, and Input types. For the previous Object-only behavior, switch to theobjectFieldFilteroption. - Breaking
Unused
fieldNodesutility functions have been removed. - Breaking
Unused
typeContainsSelectionSetfunction has been removed, andtypesContainSelectionSethas been moved to thestitchpackage. - Breaking
Unnecessary
Operationtype has been removed in favor ofOperationTypeNodefrom upstream graphql-js. - Breaking
As above,
applySchemaTransforms/applyRequestTransforms/applyResultTransformshave been removed from theutilspackage, as they are implemented elsewhere or no longer necessary.
Related Issues
Proxy all the errors
Fix typings #1614
Disable implicit schema pruning #1817
Mocks not working for functions #1807
Patch Changes
enhance(stitching): improve error message for unknown types
Bump all packages to allow adjustments
- 9.x
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.