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

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

Open
maxschridde1494 opened this issue Sep 17, 2024 · 0 comments

Comments

@maxschridde1494
Copy link
Contributor

fetchPolicy: 'network-only',

I just finished writing a supabase GQL dataprovider. 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<IntrospectionSchema> =>
    apolloClient
        .query<IntrospectionQuery>({
            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. So it's possible this is a supabase integration specific issue, but this seems unrelated to fetch policies.

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