question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error ApolloError: Expected (a schema) to be a GraphQL schema

See original GitHub issue

Intended 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:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
fromicommented, Nov 9, 2020

I just found the reason why it was wrapped with {default: ...}: const schema = require('./schema') is not equivalent to import schemafrom './schema'. You need to do const schema = require('./schema').default

2reactions
nicosamplercommented, Sep 3, 2020

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:

Server Error
Error: Expected { default: { __validationErrors: undefined, extensions: undefined, astNode: [Object], extensionASTNodes: [], __allowedLegacyNames: [], _queryType: Query, _mutationType: Mutation, _subscriptionType: undefined, _directives: [Array], _typeMap: [Object], _possibleTypeMap: {}, _implementations: {} } } to be a GraphQL schema.

My code:

function createIsomorphLink() {
  if (typeof window === 'undefined') {
    const { SchemaLink } = require('@apollo/client/link/schema');
    const schema = require('../../graphql/schema');
    return new SchemaLink({ schema });
  } else {
    const { HttpLink } = require('@apollo/client/link/http');
    return new HttpLink({
      uri: '/api/graphql',
      credentials: 'same-origin',
    });
  }
}

schema:

Object [Module] {
  default: GraphQLSchema {
    __validationErrors: undefined,
    extensions: undefined,
    astNode: {
      kind: 'SchemaDefinition',
      directives: [],
      operationTypes: [Array],
      loc: [Object]
    },
    extensionASTNodes: [],
    __allowedLegacyNames: [],
    _queryType: Query,
    _mutationType: Mutation,
    _subscriptionType: undefined,
    _directives: [ @skip, @include, @deprecated ],
    _typeMap: [Object: null prototype] {
      Query: Query,
      User: User,
      ID: ID,
      String: String,
      Role: Role,
      Boolean: Boolean,
      Zone: Zone,
      DateTime: DateTime,
      Client: Client,
      IdType: IdType,
      ClientAddress: ClientAddress,
      Int: Int,
      ContactType: ContactType,
      ClientPhone: ClientPhone,
      Loan: Loan,
      LoanType: LoanType,
      Float: Float,
      LoanStatus: LoanStatus,
      Periodicity: Periodicity,
      Mutation: Mutation,
      CreateUserInput: CreateUserInput,
      SignInInput: SignInInput,
      SignInPayload: SignInPayload,
      ClientInput: ClientInput,
      ClientAddressInput: ClientAddressInput,
      ClientPhoneInput: ClientPhoneInput,
      LoanInput: LoanInput,
      Date: Date,
      ZoneInput: ZoneInput,
      __Schema: __Schema,
      __Type: __Type,
      __TypeKind: __TypeKind,
      __Field: __Field,
      __InputValue: __InputValue,
      __EnumValue: __EnumValue,
      __Directive: __Directive,
      __DirectiveLocation: __DirectiveLocation,
      Time: Time,
      PaymentStatus: PaymentStatus,
      PaymentType: PaymentType
    },
    _possibleTypeMap: [Object: null prototype] {},
    _implementations: [Object: null prototype] {}
  }
}

dependencies:

"@apollo/client": "^3.1.4",
"apollo-link-schema": "^1.2.5",
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found