Skip to content

Conversation

@jasonbahl
Copy link
Collaborator

What does this implement/fix? Explain your changes.

This introduces a more helpful error when a field in the Schema references a GraphQL Type that has not been registered to the Schema.

Does this close any currently open issues?

closes #3034

Any other comments?

When registering a field that references a Type that doesn't exist:

<?php
add_action( 'graphql_register_types', function() {
  register_graphql_field( 'User', 'fakeField', [
	  'type' => 'NonExistingType'
  ]);
} );

Then querying for the field like so:

{
  users {
    nodes {
      id
      fakeField
    }
  }
}

Before

A vague error was returned with limited information to quickly identify the issue.

CleanShot 2024-02-05 at 10 13 53

After

A clearer Error is returned

CleanShot 2024-02-05 at 10 14 47

@jasonbahl jasonbahl requested a review from josephfusco February 5, 2024 17:16
@jasonbahl jasonbahl self-assigned this Feb 5, 2024
@coveralls
Copy link

coveralls commented Feb 5, 2024

Coverage Status

coverage: 84.765% (+0.009%) from 84.756%
when pulling 35e49fc on jasonbahl:feat/3034-provide-better-error-when-type-does-not-exist
into f480fd2 on wp-graphql:develop.

@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit 35e49fc and detected 0 issues on this pull request.

View more on Code Climate.

@jasonbahl jasonbahl merged commit 121a691 into wp-graphql:develop Feb 8, 2024
This was referenced Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhelpful error when a non-existing type is referenced as a Field's type

2 participants