Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name operations #1700

Merged
merged 2 commits into from Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/delegate/src/Subschema.ts
Expand Up @@ -15,7 +15,7 @@ export function setObjectSubschema(result: any, subschema: GraphQLSchema | Subsc
result[OBJECT_SUBSCHEMA_SYMBOL] = subschema;
}

export function isSubschemaConfig(value: any): value is SubschemaConfig {
export function isSubschemaConfig(value: any): value is SubschemaConfig | Subschema {
return Boolean((value as SubschemaConfig).schema);
}

Expand Down
11 changes: 11 additions & 0 deletions packages/delegate/src/createRequest.ts
Expand Up @@ -32,6 +32,7 @@ export function getDelegatingOperation(parentType: GraphQLObjectType, schema: Gr

export function createRequestFromInfo({
info,
operationName,
operation = getDelegatingOperation(info.parentType, info.schema),
fieldName = info.fieldName,
selectionSet,
Expand All @@ -44,6 +45,7 @@ export function createRequestFromInfo({
fragments: info.fragments,
variableDefinitions: info.operation.variableDefinitions,
variableValues: info.variableValues,
targetOperationName: operationName,
targetOperation: operation,
targetFieldName: fieldName,
selectionSet,
Expand All @@ -58,6 +60,7 @@ export function createRequest({
fragments,
variableDefinitions,
variableValues,
targetOperationName,
targetOperation,
targetFieldName,
selectionSet,
Expand Down Expand Up @@ -130,8 +133,16 @@ export function createRequest({
selectionSet: newSelectionSet,
};

const operationName = targetOperationName
? {
kind: Kind.NAME,
value: targetOperationName,
}
: undefined;

const operationDefinition: OperationDefinitionNode = {
kind: Kind.OPERATION_DEFINITION,
name: operationName,
operation: targetOperation,
variableDefinitions: Object.keys(variableDefinitionMap).map(varName => variableDefinitionMap[varName]),
selectionSet: {
Expand Down
2 changes: 2 additions & 0 deletions packages/delegate/src/delegateToSchema.ts
Expand Up @@ -33,6 +33,7 @@ export function delegateToSchema(options: IDelegateToSchemaOptions | GraphQLSche

const {
info,
operationName,
operation = getDelegatingOperation(info.parentType, info.schema),
fieldName = info.fieldName,
returnType = info.returnType,
Expand All @@ -46,6 +47,7 @@ export function delegateToSchema(options: IDelegateToSchemaOptions | GraphQLSche
fieldName,
selectionSet,
fieldNodes,
operationName,
});

return delegateRequest({
Expand Down
3 changes: 3 additions & 0 deletions packages/delegate/src/types.ts
Expand Up @@ -35,6 +35,7 @@ export type DelegationBinding = (delegationContext: DelegationContext) => Array<

export interface IDelegateToSchemaOptions<TContext = Record<string, any>, TArgs = Record<string, any>> {
schema: GraphQLSchema | SubschemaConfig | Subschema;
operationName?: string;
operation?: Operation;
fieldName?: string;
returnType?: GraphQLOutputType;
Expand All @@ -58,6 +59,7 @@ export interface IDelegateRequestOptions extends Omit<IDelegateToSchemaOptions,

export interface ICreateRequestFromInfo {
info: GraphQLResolveInfo;
operationName?: string;
operation: Operation;
fieldName: string;
selectionSet?: SelectionSetNode;
Expand All @@ -72,6 +74,7 @@ export interface ICreateRequest {
variableDefinitions?: ReadonlyArray<VariableDefinitionNode>;
variableValues?: Record<string, any>;
targetOperation: Operation;
targetOperationName?: string;
targetFieldName: string;
selectionSet?: SelectionSetNode;
fieldNodes?: ReadonlyArray<FieldNode>;
Expand Down