Skip to content

Commit

Permalink
add test for questioned spec bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Oct 30, 2024
1 parent d59c725 commit 46446ed
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions src/execution/__tests__/questioned-spec-bug-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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 { 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 rootValue = {
someInterface: {
__typename: 'SomeType',
echo: ({ value }: { value: string }) => value,
},
};

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 }],
},
],
});

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

expectJSON(errors).toDeepEqual([
{
// This would pass validation for the interface, but we get a runtime error above.
message:
'Argument "SomeType.echo(value:)" of type "String!" is required, but it was not provided.',
locations: [{ line: 5, column: 13 }],
},
]);
});
});

0 comments on commit 46446ed

Please sign in to comment.