"Must Provide Schema Definition" error using apollo-client

I’m having an issue getting graphql queries working outside of the playground. My app is built in react using apollo-client. fauna is returning the following response to my request
{"data":null,"errors":[{"message":"Must provide schema definition with query type or a type named Query."}]}

The query itself is fine, works a treat in the Playground (sorry for horrible formatting from console…)
query: "{↵ allTracks {↵ data {↵ title↵ main_artists {↵ data {↵ name↵ __typename↵ }↵ __typename↵ }↵ composers {↵ data {↵ name↵ __typename↵ }↵ __typename↵ }↵ links {↵ data {↵ url↵ __typename↵ }↵ __typename↵ }↵ __typename↵ }↵ __typename↵ }↵}↵" variables: {}

At a bit of a loss as to what this error means. I do have the query allTracks in my schema. Help would be much appreciated! None of the valid variations make a difference…
query: GetAllTracks { allTracks ... query: { allTracks ...

The full query in the code, wrapped by gql formatted is
export const GET_ALL_TRACKS = gql query { allTracks { data { title main_artists { data { name } } composers { data { name } } links { data { url } } } } }

The implemention for the query uses the apollo-client useQuery hook.
const { loading, error, data } = useQuery(GET_ALL_TRACKS,{errorPolicy: 'all'});

Are you providing the schema you imported to Fauna, or the result that Fauna generates? The schema you import is not actually the one that is hosted.

There is no schema provided or necessary as I’m just using apollo-client which just handles the query request and response to fauna, rather than as a server. I managed to fix the issue seeing an old tip from another user that the issue was actually something to do with authentication.

I created a new admin key and used that, rather than the server key I was using. I can’t see why this should be the case as the query was read only, but that did make the error go away. It seems the error given out by fauna in this case isn’t very helpful. Maybe you guys can look at that?

That’s right! I got hung up on delegating the schema, which I’ve done before. It’s definitely what the error message makes me think of.

That is strange. Keys with the “server” role should have access to all collections and indexes.

I don’t work for Fauna, but I agree! Someone else should look at this.

What is the “old tip”? Is it from somewhere else in the Forums? Stack Overflow? Slack? Can you link to it?

Oh sorry, yes hope they see this! Thanks for your input on trying to solve.

This was the original post I found https://stackoverflow.com/questions/60013634/faunadb-graph-query-returns-error-must-provide-schema-definition-with-query/60045590#60045590

1 Like