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

fix: Parse query root interfaces #2816

Merged
merged 3 commits into from
Feb 8, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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