Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing field in Apollo GraphQL Query

I'm using react with Apollo and a F# backend.

When i make a query i get an error similar to this but i'm not sure why as it seems like stories is present in the response.

Missing field stories in "{\"stories\":[{\"name\":\"Story1\",\"__typename\":\"Story\"},{\"name\":\"Story2\",\"__typename\":\

My code for making the query is:

const client = new ApolloClient({
    uri: '/graphql',
});

client
    .query({
        query: gql`
      query testStoryQuery
    {

        stories
        {
            name

        }

    }
    `
    })
    .then(result => console.log(result));

Finally the raw response returned by the server is:


{"data":"{\"stories\":[{\"name\":\"Story1\",\"__typename\":\"Story\"},{\"name\":\"Story2\",\"__typename\":\"Story\"},{\"name\":\"Story3\",\"__typename\":\"Story\"}]}"}

The only thing I've tried so far is jsonifying the response (i.e. the ") around fields, but it doesn't seem to find the field either way.

Update (extra info)

The full stack trace

Stack trace of the browser error

Any help would be appreciated, i'll continue working on it in the meantime.

Thank you :)

like image 843
John Johnson Avatar asked Oct 17 '25 04:10

John Johnson


1 Answers

Bad response format:

{"data":____"____{\"stories\":[{\"name\":\"Story1\",\"__typename\":\"Story\"},{\"name\":\"Story2\",\"__typename\":\"Story\"},{\"name\":\"Story3\",\"__typename\":\"Story\"}]}____"____}

This way data is a string, not object.

Also bad names \r\n\t\t\t\t__typename in a stack trace.

For more details run some working example (any apollo client project) and compare arguments passed to writeToStore.ts methods using browser debugger breakpoints.

like image 154
xadm Avatar answered Oct 19 '25 20:10

xadm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!