error ApolloError: Expected (a schema) to be a GraphQL schema
See original GitHub issueIntended outcome:
Actual outcome:
How to reproduce the issue:
Versions
After upgrading to Apollo Client 3, my SSR no longer connects via Apollo-Schema-Link. Getting the error.
error ApolloError: Expected { __validationErrors: undefined, extensions: undefined, astNode: undefined, extensionASTNodes: [], __allowedLegacyNames: [], _queryType: Query, _mutationType: Mutation, _subscriptionType: null, _directives: [@skip, @include, @deprecated], _typeMap: { Query: Query, Int: Int, Boolean: Boolean, PotentialSeries: PotentialSeries, ID: ID, String: String, Float: Float, User: User, Email: Email, Vote: Vote, Sub: Sub, Date: Date, __Schema: __Schema, __Type: __Type, __TypeKind: __TypeKind, __Field: __Field, __InputValue: __InputValue, __EnumValue: __EnumValue, __Directive: __Directive, __DirectiveLocation: __DirectiveLocation, AffiliateSalesInput: AffiliateSalesInput, Subscriptions: Subscriptions, TagInput: TagInput, ViewLog: ViewLog, ContentType: ContentType }, _possibleTypeMap: {}, _implementations: {} } to be a GraphQL schema.
Not sure what’s changed here, but I’m using the proper imports
import { renderToStringWithData } from '@apollo/client/react/ssr'
import { SchemaLink } from '@apollo/client/link/schema'
import {
ApolloClient,
ApolloLink,
InMemoryCache,
ApolloProvider,
} from '@apollo/client'
const schemaLink = new SchemaLink({
schema,
context: { user, userId: user ? user._id : undefined },
})
const client = new ApolloClient({
ssrMode: true,
link: schemaLink,
cache,
})
Not sure how the schema that I’m passing in is suddenly no longer a valid GraphQL Schema. The error only shows up in useQuery return errors. Not seeing an error anywhere else.
This same setup worked up until moving off of apollo-client rc’s and moving to the new import { SchemaLink } from '@apollo/client/link/schema'
import.
I don’t have a reproduction because of how complex these things are, but seeing as how the same code worked with the release candidate, it seems like a bug to me.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Error: Expected undefined to be a GraphQL schema
I am getting an error which says " Error: Expected undefined to be a GraphQL schema." Please check what issue is this when...
Read more >Error handling - Apollo GraphQL Docs
The request was parsed successfully and is valid against the server's schema, but the server couldn't resolve which operation to run.
Read more >Error: Expected {} to be GraphQL Schema - Prisma 1 Forum
Hello everyone, I am currently working on a project where I have created my datamodel files, generated the javascript prisma library and am ......
Read more >Top GraphQL Errors and How to fix them
Error handling in GraphQL is different on both server & client-side ... malformed query; syntax or schema logic; variables and fragments not ...
Read more >Handling GraphQL errors like a champ with unions and ...
Error handling can be frustrating in GraphQL. ... Unfortunately, the error codes don't follow any schema (at least not according to the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just found the reason why it was wrapped with
{default: ...}
:const schema = require('./schema')
is not equivalent toimport schemafrom './schema'
. You need to doconst schema = require('./schema').default
I’m facing the same issue here, I can use the schema in the client perfectly fine but when I try to use it with SSR fails with this error:
My code:
schema:
dependencies: