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

graphql introspection returns null data #2397

Closed
audunhalland opened this issue Oct 6, 2018 · 0 comments
Closed

graphql introspection returns null data #2397

audunhalland opened this issue Oct 6, 2018 · 0 comments

Comments

@audunhalland
Copy link
Contributor

audunhalland commented Oct 6, 2018

Using ra-data-opencrud (https://github.com/Weakky/ra-data-opencrud) which again uses introspection.js in ra-data-graphql:

What you were expecting:
I would expect introspection not to crash, because inspecting the network request shows that there is in fact a valid schema returned by the server.

What happened instead:
the graphql introspection query throws an error:

Uncaught (in promise) TypeError: Cannot read property '__schema' of null
    at introspection.js:76

Steps to reproduce:

  1. Run a Prisma server which returns a valid response to introspection at localhost:4466
  2. Create a simple react app using OpenCrud provider

Related code:

import React, { Component } from 'react';
import buildOpenCrudProvider from 'ra-data-opencrud';
class App extends Component {
  ...
  componentDidMount() {
    buildOpenCrudProvider({ clientOptions: { uri: 'http://localhost:4466/' } })
      .then(dataProvider => this.setState({ dataProvider }));
  }
  ...
}

Other information:
A bit of investigation from my end points in the direction of fetchPolicy in apollo client. React-admin already sets fetchPolicy: 'network-only' for ordinary graphql queries, (which I figure is a fix for this exact problem) but not for the introspection. A related apollo-client issue is apollographql/apollo-client#3030, but it appears it has never been properly fixed. I suggest setting fetchPolicy: 'network-only' to the introspection query also to work around this bug in apollo-client.

Environment

  • React-admin version: 2.3.3
  • Last version that did not exhibit the issue (if applicable):
  • React version: 16.4.14
  • Browser: any Chrome/Firefox
  • Stack trace (in case of a JS error):

The crashing code in is in packages/ra-data-graphql/src/introspection.js:

export default async (client, options) => {
    const schema = options.schema
        ? options.schema
        : await client
              .query({
                  query: gql`
                      ${introspectionQuery}
                  `,
              })
              .then(({ data: { __schema } }) => __schema); // <-- crashes here: data is null
    ...
};
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

1 participant