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

How to identify why GraphQL fields are missing? #4271

Closed
RobertBolender opened this issue Feb 27, 2018 · 8 comments
Closed

How to identify why GraphQL fields are missing? #4271

RobertBolender opened this issue Feb 27, 2018 · 8 comments

Comments

@RobertBolender
Copy link
Contributor

Context: I'm using gatsby-source-wordpress with lots of ACF fields

I frequently run into errors similar to this one: #4267
Most of the time I'm able to determine why a field is missing, usually because the field has a blank value on a single post somewhere.

@ GraphQL Error There was an error while compiling your site's GraphQL queries.
@   Invariant Violation: GraphQLParser: Unknown field `features` on type `acf_26`. Source: document `property` file: `GraphQL request`.
@

Is there an easier way to determine why an ACF field is failing to compile to GraphQL? I'm already using gatsby build --verbose, is there an additional layer of verbosity I can add to the GraphQL step?

I've tried looking in GraphiQL and the field is just missing, doesn't give me any additional information at this point.

@pieh
Copy link
Contributor

pieh commented Feb 27, 2018

Hi, currently there's not easy way to do it - I work on this ( #3905 ) but for now had to put in on hold to get more spare time to do some performance testing as this does change the way gatsby gathers field types from data.

You best bet currently is to examine your wordpress REST endpoints - you can see them if you have verbose output enabled for wordpress plugin: it would be something like https://<wordpress_url>/wp-json/wp/v2/pages (for pages) and check what data it shows for acf -> features fields - it's very often false if value wasn't entered, and gatsby will treat that as type conflict if it's for example string or object in other pages/posts

@RobertBolender
Copy link
Contributor Author

Hmm, I'm looking at the WP REST endpoints and I see all my fields there, including the features field with the values I would expect (arrays).

@jlengstorf
Copy link
Contributor

@awesomebob Does every instance of that field return an array? I ran into this with one of my fields where it was returning a boolean for unset fields, which broke the type checking as @pieh described.

@RobertBolender
Copy link
Contributor Author

@jlengstorf In this case, yes every instance. I've seen the boolean error several times as well, as recently as this morning:

@ GraphQL Error Field "gallery" must not have a selection since type "Boolean" has no subfields.

@RobertBolender
Copy link
Contributor Author

Just throwing this out there, this is my only ACF field for which the value is an array of strings (checkbox field), could that be an issue? It was working just fine until this morning.

@pieh
Copy link
Contributor

pieh commented Feb 27, 2018

Are arrays always arrays of string or are they are sometimes arrays of string, sometimes arrays of booleans? Array with mixed types is considered as mixed type too.

You can try locally edit node_modules/gatsby/dist/schema/data-tree-utils.js function extractFieldExamples and add

if (key === 'features') {
  console.log('conflict', obj, next)
}

in places where it returns INVALID_VALUE to see what values it considers as conflicts (it won't tell you where they are, but will tell you what they are). If this is array then probably if (!areAllSameType(array)) return INVALID_VALUE will discard this field.

@RobertBolender
Copy link
Contributor Author

RobertBolender commented Feb 27, 2018

@pieh thanks, I'm trying that now. My builds are taking much longer than usual, but hopefully I'll find something with this.

My arrays should always be arrays of strings, but we'll see.

@RobertBolender
Copy link
Contributor Author

RobertBolender commented Feb 28, 2018

It appears that my array is internally converted to an object by Gatsby at some point

It appears that some of my arrays are objects with numeric keys. possibly because they aren't strictly sequential indexes (indices?). The numeric keys are prefixed with wordpress_ to make them valid for GraphQL.

conflict:
[ 'vintage' ]
{ wordpress_0: 'pool',
  wordpress_1: 'barn',
  wordpress_3: 'vintage',
  wordpress_4: 'waterview' }

conflict:
[ 'none' ]
{ wordpress_0: 'pool',
  wordpress_1: 'barn',
  wordpress_3: 'vintage',
  wordpress_4: 'waterview' }

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

No branches or pull requests

3 participants