marmelab / marmelab/react-admin

ra-data-graphql Introspection Result Generation Affected by Apollo Client Cache Policy

Open
#10,215 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
26.9k
Forks
5.5k
Avg merge
2d 3h
Merged PRs (30d)
19

Description

https://github.com/marmelab/react-admin/blob/fcb38f4d55c79fe22d6bd59c56e23eb4b49b0b1b/packages/ra-data-graphql/src/introspection.ts#L58

I just finished writing a [supabase GQL dataprovider](https://github.com/maxschridde1494/ra-data-graphql-supabase). I am experiencing trouble with the dynamic introspectionResult generation. It is erroring out silently, resulting in an introspectionResult with an empty resources array and data provider errors:

`
Error: Unknown resource players. Make sure it has been declared on your server side schema. Known resources are
at buildQuery2 (buildQuery.ts:24:23)
at index.ts:183:15
at step (introspection.ts:154:5)
at Object.next (introspection.ts:154:5)
at fulfilled (introspection.ts:154:5)
`

Digging into the introspectionResult generation in `ra-data-graphql`, the introspection query response includes verbose types:

```
{
"kind": "SCALAR",
"name": "BigFloat",
"fields": null,
"__typename": "BigFloat",
"enumValues": [],
"interfaces": [],
"description": "A high precision floating point value represented as a string",
"inputFields": null,
"possibleTypes": null
}
```

However, the apollo client seems to be transforming this and my returned schema from the apollo client has a trimmed version of the type objects that only include `__typename`:

```
{
__typename: 'BigFloat'
}
```

My current workaround is to fetch the schema myself using a fetch policy of `no-cache` and pass that into the data provider init.

```
...
const introspection: IntrospectionOptions = {
...defaultIntrospection
}

const fetchSchema = (): Promise =>
apolloClient
.query({
fetchPolicy: 'no-cache',
query: gql`
${getIntrospectionQuery()}
`,
})
.then(({ data: { __schema } }) => __schema);

export async function initDataProvider(options?: any) {
introspection.schema = await fetchSchema()

return buildGraphQLProvider({
bulkActionsEnabled: true,
client: apolloClient,
introspection,
...options,
})
}
```

Of note, I have never run into this issue with `ra-data-graphql-simple` or [ra-data-graphql-advance](https://github.com/maxschridde1494/ra-data-graphql-advanced). So it's possible this is a supabase integration specific issue, but this seems unrelated to fetch policies.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at packages/ra-data-graphql/src/introspection.ts#L58 and trace how the Apollo Client introspection response becomes the generated introspectionResult. Reproduce the empty resources array with the Supabase GraphQL provider and compare cached results with the no-cache schema fetch shown in the issue. Done means dynamic introspection preserves the schema details needed to discover resources and avoids the reported data provider errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.