Skip to content

Commit

Permalink
fix: Parse query root interfaces (#2816)
Browse files Browse the repository at this point in the history
  • Loading branch information
calvincestari authored Feb 8, 2023
1 parent f44d5b8 commit 9cf9eeb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
DocumentNode,
GraphQLEnumType,
GraphQLInputObjectType,
GraphQLInterfaceType,
} from "graphql";
import {
readFileSync
Expand Down Expand Up @@ -92,3 +93,39 @@ describe("mutation defined using ReportCarProblemInput", () => {
});
});
});

describe("query with selections", () => {
const documentString: string = `
query fetchMyString {
missingInterfaceString
}
`;

const document: DocumentNode = parseOperationDocument(
new Source(documentString, "Test Query", { line: 1, column: 1 }),
false
);

describe("given interface on root query", () => {
const schemaSDL: string = `
interface MissingInterface {
missingInterfaceString: String!
}
type Query implements MissingInterface {
missingInterfaceString: String!
}
`;

const schema: GraphQLSchema = loadSchemaFromSources([new Source(schemaSDL, "Test Schema", { line: 1, column: 1 })]);

it("should compile with referencedTypes including interface", () => {
const compilationResult: CompilationResult = compileDocument(schema, document, false, emptyValidationOptions);
const validInterface: GraphQLInterfaceType = compilationResult.referencedTypes.find(function(element) {
return element.name == 'MissingInterface'
}) as GraphQLInterfaceType

expect(validInterface).not.toBeUndefined()
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export function compileToIR(
const rootType = schema.getRootType(operationType) as GraphQLObjectType;
const [directives,] = compileDirectives(operationDefinition.directives) ?? [undefined, undefined];

referencedTypes.add(getNamedType(rootType));
addReferencedType(rootType)

return {
name,
Expand Down

0 comments on commit 9cf9eeb

Please sign in to comment.