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

add test for questioned spec bug #4272

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
95 changes: 95 additions & 0 deletions src/execution/__tests__/questioned-spec-bug-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { describe, it } from 'mocha';

import { expectJSON } from '../../__testUtils__/expectJSON.js';

import { parse } from '../../language/parser.js';

import type { GraphQLSchema } from '../../type/schema.js';
import { validateSchema } from '../../type/validate.js';

import { validate } from '../../validation/validate.js';

import { buildSchema } from '../../utilities/buildASTSchema.js';

import { execute } from '../execute.js';

async function executeQuery(args: {
schema: GraphQLSchema;
query: string;
rootValue?: unknown;
}) {
const { schema, query, rootValue } = args;
const document = parse(query);
return execute({
schema,
document,
rootValue,
});
}

describe('Execute: default arguments', () => {
it('handles interfaces with fields with default arguments', async () => {
const schema = buildSchema(`
type Query {
someInterface: SomeInterface
}

interface SomeInterface {
echo(value: String! = "default"): String
}

type SomeType implements SomeInterface {
echo(value: String!): String
}
`);

const query = `
{
someInterface {
... on SomeType {
echo
}
echo
}
}
`;

const schemaErrors = validateSchema(schema);

expectJSON(schemaErrors).toDeepEqual([]);

const queryErrors = validate(schema, parse(query));

expectJSON(queryErrors).toDeepEqual([
{
// This fails validation only for the object, but passes for the interface.
message:
'Argument "SomeType.echo(value:)" of type "String!" is required, but it was not provided.',
locations: [{ line: 5, column: 13 }],
},
]);

const rootValue = {
someInterface: {
__typename: 'SomeType',
echo: 'Runtime error raised, not called!',
},
};

expectJSON(await executeQuery({ schema, query, rootValue })).toDeepEqual({
data: {
someInterface: {
echo: null,
},
},
errors: [
{
message:
'Argument "value" of required type "String!" was not provided.',
path: ['someInterface', 'echo'],
locations: [{ line: 5, column: 13 }],
},
],
});
});
});
Loading