Skip to content

Commit

Permalink
fix: validation caching schema check (#2720)
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Apr 25, 2023
1 parent 76ca97b commit cc37069
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-oranges-warn.md
@@ -0,0 +1,5 @@
---
'graphql-yoga': patch
---

Skip validation caching when there is no `schema` specified. This previously caused a cryptic error message when reaching execution/validation without a schema. Now the missing schema error will actually originate from within the `validate` function instead.
10 changes: 10 additions & 0 deletions packages/graphql-yoga/__tests__/schema.spec.ts
Expand Up @@ -7,6 +7,10 @@ describe('schema', () => {
it('missing schema causes a error', async () => {
const yoga = createYoga({
logging: false,
maskedErrors: {
/** We use dev mode in order to verify that our error message is originating from within graphql-js and not our code. */
isDev: true,
},
})

const response = await yoga.fetch('http://yoga/graphql', {
Expand All @@ -25,6 +29,12 @@ describe('schema', () => {
errors: [
{
message: 'Unexpected error.',
extensions: {
/** This error is raised by Graphql.js */
originalError: {
message: 'Expected null to be a GraphQL schema.',
},
},
},
],
})
Expand Down
Expand Up @@ -57,6 +57,11 @@ ParserAndValidationCacheOptions): Plugin<{}> {
setResult,
// eslint-disable-next-line @typescript-eslint/ban-types
}): void | AfterValidateHook<{}> {
/** No schema no cache */
if (schema == null) {
return
}

if (validationCache !== false) {
const rulesKey =
rules?.map((rule: ValidationRule) => rule.name).join(',') || ''
Expand Down

0 comments on commit cc37069

Please sign in to comment.