Closed gabrielhpugliese closed 3 years ago
Any updates here? Unfortunately I recently run into the same issue...
Hey, @gabrielhpugliese. Thanks for reporting this.
Could you please share the code where you make an actual GraphQL query?
I'm putting this into a test case and it passes without issues. This implies the problem may be either in how the actual query is made, or how the GraphQL client is used. I can elaborate more once you provide more info. Thanks.
Hi @kettanaito ,
The query I've put on this original post is this one: https://github.com/gabrielhpugliese/MediaMarktSaturn/blob/b2061e1c2677853f8ca614ee79fe6acafd9622a7/src/lib/queries.ts#L23
If you take a closer look into the file and the switch case in the end of the file, you will see I return queries for prod and test envs. If you compare the same query for the test env you will see that I rip off a big part of the query in order to run it. It kinda works but it's a bit hacky. It does not work on the browser == dev env. The same query for dev is in this line: https://github.com/gabrielhpugliese/MediaMarktSaturn/blob/b2061e1c2677853f8ca614ee79fe6acafd9622a7/src/lib/queries.ts#L180
Thank you for the follow-up. Queries are good, the main interest goes to which GraphQL client you're u sing. It appears that's Apollo. There's a nuance with Apollo where it expects the data you return to have the __typename
property describing the type of the data. Apollo is likely to strip the data that doesn't have the __typename
property, that's why this scenario works fine in isolation but results in empty nodes
with queried with Apollo.
We mention this in the GraphQL integration, but it's not the most evident issue to catch.
I don't see any explicit __typename
when inspecting the GitHub Explorer's response, so I may only suggest adding this to your nodes
in the mocked data:
{
node: {
__typename: 'Repository',
// ...the rest of properties you have (i.e. "id", "description", etc.)
}
}
Could you please try this and let me know?
Hi @kettanaito, thanks a lot for that hint. Indeed with adding the __typename it works for me 👍
Note: In my project I'm using Typescript and created the types for my graphql queries and mutation with the graphql-codegen . Initially I configured it to skip the typename propery wherefore in the handler this property was not offered / allowed. Now the typenames are not skipped and when setting them correctly all requests are resolved as expected 👍
Many thanks @kettanaito and @netcoding87 . I will try it whenever possible, right now I am really busy! But thanks again!
Describe the bug
I am trying to mock Github's public GraphQL API. I am trying to fetch public repositories. Whenever I try to incorporate a fragment on the query, something happens (still trying to understand) and the response is not properly returned.
Environment
msw: ^0.27.0
nodejs: v12.17.0
npm: 6.14.4
yarn: 1.22.5
Chrome Version 88.0.4324.96 (Official Build) (x86_64)
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I expect that it would just work as when I do not use the incorporation. Works fine if I want to mock anything that does not use incorporation.
Screenshots
Not screenshot but a payload I am using to mock: