简体   繁体   中英

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 (ie the ") around fields, but it doesn't seem to find the field either way.

Update (extra info)

The full stack trace

浏览器错误的堆栈跟踪

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

Thank you :)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM