markhuot / craftql

A drop-in GraphQL server for Craft CMS
Other
320 stars 53 forks source link

Error: Can't query field entries on type Query – but it actually works #313

Closed Jones-S closed 5 years ago

Jones-S commented 5 years ago

I am using a query like:

query Page($slug: String!) {
  entries(section:[pages], slug: $slug) {
    slug
    title

  }
}

Within graphiql it gives me this error

image

But when I run the command I get what I wanted. So it actually works... Does anyone know if the error is wrong or if my query indeed is wrong?

Thank you

Cheers

narration-sd commented 5 years ago

Look up 'inline fragments' on Types, Jonas.

How you get any but the most primary Element fields.

Grüss

Jones-S commented 5 years ago

Thank you for the quick response. I'll check it out. --- Edit:

If I read this correctly: (from https://graphql.org/learn/queries/#inline-fragments)

... on Droid {
        primaryFunction
    }

The ...on part is an inline fragment, correct?

But why would that be important in my case. I use ...on stuff later for matrix fields.

As far as I understand inline Fragments are used in cases where the type is not just one. But in my case it is. Or am I completely misunderstanding something?

narration-sd commented 5 years ago

You need them any time the fields are not part of the primary target, which in Craft's case is Element.

You are presumably querying on an Entry. Then any fields you add as properties of its Section,, your fields defined for it, will only be present on the compound type GraphQL generates.

That's why there's emphasis on the 'Documentation' or 'Schema' abilities in Graphiql -- so you can look these types up, as the Craft Entry Type of interest often also forms part of the compound name.

In CraftQL syntax, the first entry type is [often?] merged with the base name, so yes, as you suggest,

    ... on Droid {
        body    # body is field of your Droid Entry, not of Element...
        image {
             title
             url
        }
        primaryFunction  # etc.
    }

In the new Craft GraphQL syntax, it's further spelled out, so something like this:

    ... on Droid_droid_Entry {
        body
        image {
             title
             url
        }
        primaryFunction  # etc.
    }

Gruezi, properly this time

Jones-S commented 5 years ago

Grüezi is rather used as a greeting :).

Thanks for elaborating, I still don't fully understand. I will try to read some stuff about 'Documentation' or 'Schema' abilities in Graphiql.

But also today, the same query is not warning me at all, and everything looks fine. Maybe it was a bug?...

narration-sd commented 5 years ago

I can tell you what the situation looks like...

Ok, and thanks for reminding me where speech also places Gruezi, so I should have known for notes also - it was a late night instant. Mainly I was intending to be polite without the Hochdeutsch, which I could also know better. My time was very busy, full of Germans who wanted to polish their English on the demanding and largely non-technical matters we dealt with across many cultures constantly, thus with no chance to do formal language study. I like to keep up a bit with what I could do reasonably, read newspapers, and so the FAZ, Süddeutsch Zeitung, and Basler posts are in my in-tray...

Anyway, I should say that I much liked, appreciated, and enjoyed Switzerland, through all efforts and struggles of the times. I'd still be happily living there, with the planned brass plate on the doorpost, if those times hadn't intervened.

Jones-S commented 5 years ago

OK wow. What a long and complete answer. Thank you very much. I am not sure what could have caused the error. Maybe a thing with the token settings, but this would not explain why I got a return for my query. If it reappears I try to go through each of your points. Thank you.

Gurpreet5028 commented 3 years ago

@narration-sd thanks man beena huge help, right on the time i needed , appreciated