Registry / devops / ra-data-graphql

ra-data-graphql

JSON →
library5.14.7jsnpmunverified

Low-level GraphQL data provider for react-admin based on Apollo Client and introspection queries (v5.14.7). This package is not intended for direct use; instead, use it as a base for custom GraphQL adapters like ra-data-graphql-simple. Released alongside react-admin, its stable version follows react-admin's release cadence. Differentiators: provides a flexible introspection-based approach to map React-Admin CRUD operations to GraphQL queries/mutations, but requires a custom buildQuery function. Peer dependencies: graphql ^15.6.0 || ^16 and ra-core ^5.0.0. Ships TypeScript types.

npm install ra-data-graphql
INSTALL
IMPORT
SIG · RA-DATA-GRAPHQL
R
ra-data-graphql
devopsjavascriptv5.14.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (buildGraphQLProvider)
import buildGraphQLProvider from 'ra-data-graphql'
import { buildGraphQLProvider } from 'ra-data-graphql'
The package exports a default function, not a named export. Common mistake is to use named import.
ApolloClient
import { ApolloClient } from '@apollo/client'
import { ApolloClient } from 'ra-data-graphql'
ApolloClient is not re-exported from ra-data-graphql; it must be imported from '@apollo/client' separately.
gql
import { gql } from 'graphql-tag'
import { gql } from 'ra-data-graphql'
gql is not part of ra-data-graphql; it is typically used with Apollo Client via graphql-tag.

Shows how to build a GraphQL data provider using introspection and custom buildQuery, with Apollo Client.

import buildGraphQLProvider from 'ra-data-graphql'; import { ApolloClient, InMemoryCache } from '@apollo/client'; import { Admin, Resource } from 'react-admin'; import { PostList, PostEdit, PostCreate } from './posts'; const client = new ApolloClient({ uri: process.env.REACT_APP_GRAPHQL_URI || 'http://localhost:4000/graphql', cache: new InMemoryCache(), }); const buildQuery = introspectionResults => { // Custom logic to map react-admin requests to GraphQL queries return (fetchType, resource, params) => { // Example: return query for GET_LIST return { query: gql` query GetPostList($page: Int, $perPage: Int) { posts(page: $page, perPage: $perPage) { id title } } `, variables: { page: params.pagination.page, perPage: params.pagination.perPage }, parseResponse: response => ({ data: response.data.posts, total: response.total, }), }; }; }; const App = () => { const [dataProvider, setDataProvider] = useState(null); useEffect(() => { buildGraphQLProvider({ client, buildQuery }).then(provider => setDataProvider(() => provider) ); }, []); if (!dataProvider) return <div>Loading...</div>; return ( <Admin dataProvider={dataProvider}> <Resource name="Post" list={PostList} edit={PostEdit} create={PostCreate} /> </Admin> ); };
Debug
Known issues
gotchaThis package is a low-level library; do not use it directly unless you are building a custom adapter. For typical use, use ra-data-graphql-simple or ra-data-graphql-amsterdam.
fix
Install ra-data-graphql-simple instead: npm install ra-data-graphql-simple
affects: all
breakingIn react-admin v5, ra-data-graphql no longer includes Apollo Client as a dependency. You must provide an ApolloClient instance or use the default from @apollo/client.
fix
Install @apollo/client and pass a client instance to buildGraphQLProvider.
affects: >=5.0.0
gotchaThe buildQuery function receives introspection results asynchronously, but the provider must be constructed before the UI renders. Use state and useEffect to defer rendering.
fix
Use useState and useEffect to call buildGraphQLProvider and only render <Admin> after provider is ready.
affects: all
deprecatedThe ra-data-graphql package is transitioning to use @apollo/client v3. If you are still on Apollo v2, you may encounter compatibility issues.
fix
Upgrade to @apollo/client v3 and ensure graphql peer dependency is ^15.6.0 || ^16.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'data' of undefined
The buildQuery parseResponse expects data in a certain structure, but the GraphQL response doesn't match.
fix
Check the GraphQL response and adjust parseResponse to match the actual data shape. Ensure the query returns the expected fields.
Module not found: Can't resolve 'graphql-tag'
Missing graphql-tag dependency when using gql template literal.
fix
Install graphql-tag: npm install graphql-tag
Invariant Violation: The 'client' option is required to use GraphQLProvider
No ApolloClient instance was provided to buildGraphQLProvider.
fix
Create an ApolloClient instance and pass it in the options: buildGraphQLProvider({ client })
Upgrade
Version history
5.14.7latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency
ra-corerequiredpeer dependency
Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
ra-data-graphql — npm install ra-data-graphql · libregistry