@pothos/plugin-sub-graph
Advanced tools
Comparing version 4.1.0 to 4.2.0
# Change Log | ||
## 4.2.0 | ||
### Minor Changes | ||
- de28b57: Add explicitlyIncludeType option to subGraph options | ||
## 4.1.0 | ||
@@ -4,0 +10,0 @@ |
import type { FieldNullability, FieldRequiredness, InputFieldMap, InputShapeFromTypeParam, InputType, InterfaceParam, RootName, SchemaTypes, TypeParam } from '@pothos/core'; | ||
import type { GraphQLNamedType } from 'graphql'; | ||
import type { PothosSubGraphPlugin } from '.'; | ||
@@ -37,2 +38,3 @@ declare global { | ||
fieldsInheritFromTypes?: boolean; | ||
explicitlyIncludeType?: (type: GraphQLNamedType, subGraphs: Types['SubGraphs'][]) => boolean; | ||
}; | ||
@@ -39,0 +41,0 @@ } |
@@ -7,3 +7,3 @@ import './global-types'; | ||
export declare class PothosSubGraphPlugin<Types extends SchemaTypes> extends BasePlugin<Types> { | ||
static createSubGraph(schema: GraphQLSchema, subGraph: string[] | string): GraphQLSchema; | ||
static createSubGraph<Types extends SchemaTypes>(schema: GraphQLSchema, subGraph: string[] | string, builder: PothosSchemaTypes.SchemaBuilder<Types>): GraphQLSchema; | ||
static filterTypes(types: readonly GraphQLNamedType[], subGraphs: string[]): Map<string, GraphQLNamedType>; | ||
@@ -10,0 +10,0 @@ static filterFields(type: GraphQLInterfaceType | GraphQLObjectType, newTypes: Map<string, GraphQLNamedType>, subGraphs: string[]): () => GraphQLFieldConfigMap<unknown, unknown>; |
import type { FieldNullability, FieldRequiredness, InputFieldMap, InputShapeFromTypeParam, InputType, InterfaceParam, RootName, SchemaTypes, TypeParam } from '@pothos/core'; | ||
import type { GraphQLNamedType } from 'graphql'; | ||
import type { PothosSubGraphPlugin } from './index.js'; | ||
@@ -45,2 +46,3 @@ declare global { | ||
fieldsInheritFromTypes?: boolean; | ||
explicitlyIncludeType?: (type: GraphQLNamedType, subGraphs: Types["SubGraphs"][]) => boolean; | ||
}; | ||
@@ -47,0 +49,0 @@ } |
@@ -7,3 +7,3 @@ import './global-types.js'; | ||
export declare class PothosSubGraphPlugin<Types extends SchemaTypes> extends BasePlugin<Types> { | ||
static createSubGraph(schema: GraphQLSchema, subGraph: string[] | string): GraphQLSchema; | ||
static createSubGraph<Types extends SchemaTypes>(schema: GraphQLSchema, subGraph: string[] | string, builder: PothosSchemaTypes.SchemaBuilder<Types>): GraphQLSchema; | ||
static filterTypes(types: readonly GraphQLNamedType[], subGraphs: string[]): Map<string, GraphQLNamedType>; | ||
@@ -10,0 +10,0 @@ static filterFields(type: GraphQLInterfaceType | GraphQLObjectType, newTypes: Map<string, GraphQLNamedType>, subGraphs: string[]): () => GraphQLFieldConfigMap<unknown, unknown>; |
@@ -16,3 +16,3 @@ import './global-types.js'; | ||
export class PothosSubGraphPlugin extends BasePlugin { | ||
static createSubGraph(schema, subGraph) { | ||
static createSubGraph(schema, subGraph, builder) { | ||
const subGraphs = Array.isArray(subGraph) ? subGraph : [ | ||
@@ -57,3 +57,8 @@ subGraph | ||
...newTypes.values() | ||
].filter((type) => (isObjectType(type) || isInterfaceType(type)) && hasReturnedInterface(type)) | ||
].filter((type) => { | ||
var _builder_options_subGraphs_explicitlyIncludeType, _builder_options_subGraphs; | ||
return ((_builder_options_subGraphs = builder.options.subGraphs) === null || _builder_options_subGraphs === void 0 ? void 0 : (_builder_options_subGraphs_explicitlyIncludeType = _builder_options_subGraphs.explicitlyIncludeType) === null || _builder_options_subGraphs_explicitlyIncludeType === void 0 ? void 0 : _builder_options_subGraphs_explicitlyIncludeType.call(_builder_options_subGraphs, type, [ | ||
subGraph | ||
].flat())) || (isObjectType(type) || isInterfaceType(type)) && hasReturnedInterface(type); | ||
}) | ||
}); | ||
@@ -180,3 +185,3 @@ } | ||
if (this.options.subGraph) { | ||
return PothosSubGraphPlugin.createSubGraph(schema, this.options.subGraph); | ||
return PothosSubGraphPlugin.createSubGraph(schema, this.options.subGraph, this.builder); | ||
} | ||
@@ -183,0 +188,0 @@ return schema; |
@@ -75,3 +75,3 @@ "use strict"; | ||
class PothosSubGraphPlugin extends _core.BasePlugin { | ||
static createSubGraph(schema, subGraph) { | ||
static createSubGraph(schema, subGraph, builder) { | ||
const subGraphs = Array.isArray(subGraph) ? subGraph : [ | ||
@@ -116,3 +116,8 @@ subGraph | ||
...newTypes.values() | ||
].filter((type)=>((0, _graphql.isObjectType)(type) || (0, _graphql.isInterfaceType)(type)) && hasReturnedInterface(type)) | ||
].filter((type)=>{ | ||
var _builder_options_subGraphs_explicitlyIncludeType, _builder_options_subGraphs; | ||
return ((_builder_options_subGraphs = builder.options.subGraphs) === null || _builder_options_subGraphs === void 0 ? void 0 : (_builder_options_subGraphs_explicitlyIncludeType = _builder_options_subGraphs.explicitlyIncludeType) === null || _builder_options_subGraphs_explicitlyIncludeType === void 0 ? void 0 : _builder_options_subGraphs_explicitlyIncludeType.call(_builder_options_subGraphs, type, [ | ||
subGraph | ||
].flat())) || ((0, _graphql.isObjectType)(type) || (0, _graphql.isInterfaceType)(type)) && hasReturnedInterface(type); | ||
}) | ||
}); | ||
@@ -235,3 +240,3 @@ } | ||
if (this.options.subGraph) { | ||
return PothosSubGraphPlugin.createSubGraph(schema, this.options.subGraph); | ||
return PothosSubGraphPlugin.createSubGraph(schema, this.options.subGraph, this.builder); | ||
} | ||
@@ -238,0 +243,0 @@ return schema; |
{ | ||
"name": "@pothos/plugin-sub-graph", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "A Pothos plugin for creating multiple variants or sub-selections of the same graph", | ||
@@ -46,7 +46,7 @@ "main": "./lib/index.js", | ||
"devDependencies": { | ||
"graphql": "^16.8.1", | ||
"graphql": ">=16.6.0", | ||
"graphql-tag": "^2.12.6", | ||
"@pothos/core": "4.1.0", | ||
"@pothos/core": "4.3.0", | ||
"@pothos/plugin-errors": "4.2.0", | ||
"@pothos/plugin-relay": "4.1.0", | ||
"@pothos/plugin-relay": "4.3.0", | ||
"@pothos/plugin-with-input": "4.1.0", | ||
@@ -53,0 +53,0 @@ "@pothos/test-utils": "2.1.0" |
@@ -99,1 +99,25 @@ # SubGraph Plugin for Pothos | ||
object, a member of a union, or the type of a field argument. | ||
### Explicitly including types | ||
You can use the `explicitlyIncludeType` option to explicitly include types in a sub-graph that are | ||
unreachable. This isn't normally required, but there are some edge cases where this may be useful. | ||
For instance, when extending external references with the federation plugin, the externalRef may | ||
not be reachable directly through your schema, but you may still want to include it when building the | ||
schema. To work around this, we can explicitly include any any types that have a `key` directive: | ||
```typescript | ||
import FederationPlugin, { hasResolvableKey } from '@pothos/plugin-federation'; | ||
import SubGraphPlugin from '@pothos/plugin-sub-graph'; | ||
const builder = new SchemaBuilder<{ | ||
SubGraphs: 'Public' | 'Internal'; | ||
}>({ | ||
plugins: [SubGraphPlugin, FederationPlugin], | ||
subGraphs: { | ||
explicitlyIncludeType: (type, subGraphs) => hasResolvableKey(type) | ||
}, | ||
}); | ||
``` |
@@ -13,2 +13,3 @@ import type { | ||
import type { GraphQLNamedType } from 'graphql'; | ||
import type { PothosSubGraphPlugin } from '.'; | ||
@@ -85,2 +86,6 @@ | ||
fieldsInheritFromTypes?: boolean; | ||
explicitlyIncludeType?: ( | ||
type: GraphQLNamedType, | ||
subGraphs: Types['SubGraphs'][], | ||
) => boolean; | ||
}; | ||
@@ -87,0 +92,0 @@ } |
@@ -44,3 +44,7 @@ import './global-types'; | ||
export class PothosSubGraphPlugin<Types extends SchemaTypes> extends BasePlugin<Types> { | ||
static createSubGraph(schema: GraphQLSchema, subGraph: string[] | string) { | ||
static createSubGraph<Types extends SchemaTypes>( | ||
schema: GraphQLSchema, | ||
subGraph: string[] | string, | ||
builder: PothosSchemaTypes.SchemaBuilder<Types>, | ||
) { | ||
const subGraphs = Array.isArray(subGraph) ? subGraph : [subGraph]; | ||
@@ -90,3 +94,6 @@ | ||
types: [...newTypes.values()].filter( | ||
(type) => (isObjectType(type) || isInterfaceType(type)) && hasReturnedInterface(type), | ||
(type) => | ||
builder.options.subGraphs?.explicitlyIncludeType?.(type, [subGraph].flat()) || | ||
((isObjectType(type) || isInterfaceType(type)) && | ||
hasReturnedInterface(type as GraphQLInterfaceType | GraphQLObjectType)), | ||
), | ||
@@ -289,3 +296,3 @@ }); | ||
if (this.options.subGraph) { | ||
return PothosSubGraphPlugin.createSubGraph(schema, this.options.subGraph); | ||
return PothosSubGraphPlugin.createSubGraph(schema, this.options.subGraph, this.builder); | ||
} | ||
@@ -292,0 +299,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
118995
1631
123