Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApolloError: Cannot read property 'type' of undefined #67

Open
Freire71 opened this issue Mar 24, 2023 · 1 comment
Open

ApolloError: Cannot read property 'type' of undefined #67

Freire71 opened this issue Mar 24, 2023 · 1 comment

Comments

@Freire71
Copy link

Freire71 commented Mar 24, 2023

Hi @jneurock, I'm getting this error while trying to execute a query that does not include any "type" property. When I inspect the ApolloError object does not give any valuable information about the error location. I've got no errors while trying to seed this "Contacts" Entity, however, the MirageJS query does not work properly. Could it be some conflict of dependencies? I'm using:

"@miragejs/graphql": "^0.1.13",
"graphql": "^16.6.0",
"@apollo/client": "^3.7.4",

Apollo Client Error object

image

Query that throws this error

query clients($take: Int) {
    contacts(take: $take) {
        edges {
            id
            firstName
            lastName
            location
            photoUrl
        }
        pageInfo {
            totalCount
        }
    }
}

Server.ts queries - I'm not using automatic query handling, because of intermediary pagination types involved (edges and pageInfo). The console.log call inside the contacts query does not get triggered, I've only gotten the error. I'm assuming that this custom resolver is not working, however, the listings query works fine

        Query: {
          listings: () => ({
            edges: this.schema.all('Listing'),
            pageInfo: {
              currentPage: 0,
              itemCount: 200,
              hasNextPage: false,
              hasPreviousPage: false,
              perPage: 200,
              pageCount: 1,
            },
            contacts: () => {
              console.log('>>>>> Contact query');
              return {
                edges: this.schema.all('Contact'),
                pageInfo: {
                  totalCount: 100,
                },
              };
            },
          }),
        },
@jneurock
Copy link
Collaborator

jneurock commented Mar 29, 2023

There may be several issues. It’s a little hard to tell.

I suspect the problem with the 'type' of undefined issue has to do with missing type info in the data returned. Mirage GraphQL will take Mirage records returned from resolvers and decorate them with the necessary type info for GraphQL. If you implement a custom resolver, you either need to exclusively return Mirage records or decorate the data with the type info as needed, e.g., a __typename field. Note: I could be totally wrong here and not fully remembering how this works.

I suspect the reason the contacts resolver isn’t working is that it’s nested under listings meaning it will only be called when resolving contacts as a field of listings.

Btw, Mirage GraphQL handles Relay Pagination out-of-the-box; however, it won’t include the extra pageInfo fields like you have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants