Authentication with graphql data provider issue
See original GitHub issueI am using react-admin with simple graphql dataprovider. On backend I block all requests without token except my login endpoint. I use authProvider to make a request to login backend. However React-admin still use dataprovider on authentication page and since I don’t send an authentication token in the header before login I get an error.
Expected behavior should be: React-admin not using graphql dataprovider while loading login page.
If I allow unauthenticated requests to /graphql in the backend, I successfully see the login page.

As you see, react-admin is making a request to data-provider while loading the login page. But this is an issue since grahpql provide has only one endpoint /graphql
Here is the code that encounters the issue:
const httpLink = createHttpLink({ uri: 'http://localhost:8080/graphql' })
const authLink = setContext((_, { headers }) => {
const token = Cookies.get('accessToken')
return {
headers: {
...headers,
authorization: `Bearer ${token}`
}
}
})
const client = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache()
})
buildGraphQLProvider({
client
})
.then(dataProvider => this.setState({ dataProvider }));
So react-admin graphql dataprovider needs to access /graphql to load successfully, but that is the only endpoint for all other queries as well. I need to secure that endpoint.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:17 (6 by maintainers)

Top Related StackOverflow Question
You can use graphql codegen (https://graphql-code-generator.com/) for that
.codegen.ymlThen import the
introspection.jsonfile in your project and initialize the provider with the schema: See https://github.com/marmelab/react-admin/tree/master/packages/ra-data-graphql#introspection-optionsThat’s one way to do it but I think fixing it in the provider itself would probably be better. Postponing the introspection call until the first real dataProvider call (on a resource) for example