Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
Fix buildVariableDefinitions to use proper root type
Browse files Browse the repository at this point in the history
  • Loading branch information
timkendall committed Dec 11, 2021
1 parent edfd44b commit 30c3114
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class Selection<
const selectionSet = this.toSelectionSet();
const variableDefinitions = buildVariableDefinitions(
this.schema,
op,
selectionSet
);

Expand Down
7 changes: 4 additions & 3 deletions src/Variables.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GraphQLSchema } from "graphql";
import type { GraphQLSchema, OperationTypeNode } from "graphql";
import { Kind, visitWithTypeInfo, TypeInfo, visit } from "graphql";
import type { O, U } from "ts-toolbelt";

Expand All @@ -21,14 +21,15 @@ export const $ = <Name extends string>(name: Name): Variable<Name> =>

export const buildVariableDefinitions = <T extends SelectionSet<any>>(
schema: GraphQLSchema,
root: OperationTypeNode,
selectionSet: T
): Array<VariableDefinition<any, any>> => {
const variableDefinitions: VariableDefinition<any, any>[] = [];
const typeInfo = new TypeInfo(schema);

// @note need to wrap selectionset in operation for TypeInfo to track correctly
// @note need to wrap selectionset in an operation (root) for TypeInfo to track correctly
const operationDefinition = operation(
"query",
root,
"",
selectionSet,
variableDefinitions
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/__tests__/Variables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe("Variables", () => {
// @note we need a way to get the input type at runtime
const variableDefinitions = buildVariableDefinitions(
schema,
"query",
selectionSet(selection)
);

Expand Down Expand Up @@ -69,6 +70,7 @@ describe("Variables", () => {

const variableDefinitions = buildVariableDefinitions(
schema,
"query",
selectionSet(selection)
);

Expand Down

0 comments on commit 30c3114

Please sign in to comment.