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

Prismic graphQL and TypeScript: some types mismatch #325

Open
lausav1 opened this issue Sep 27, 2023 · 1 comment
Open

Prismic graphQL and TypeScript: some types mismatch #325

lausav1 opened this issue Sep 27, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@lausav1
Copy link

lausav1 commented Sep 27, 2023

Versions

  • @prismicio/client: v7.2.0
  • node: v16.15.1
  • graphql-request: v6.1.0
  • typescript: v4.9.5

Reproduction

I am facing some issues with TypeScript types definition when retrieving data using GraphQL:

  • The type definition of prismicClient.graphQLFetch is not corresponding to the type definition of GraphQLClient
  • Some type data, like for Slice or LinkField (they may be others - those are the ones I discovered in my implementation) are different between Rest API and GraphQL, and the current types doesn't contain the GraphQL props
Additional Details for GraphQLClient type issue

I am using GraphQLClient from graphql-request as written in your documentation here. My project is using TypeScript. When I do the following to create the GraphQLClient:

 const prismicClient = createClient(apiEndpoint, { fetch });
    const newClient = new GraphQLClient(
      getGraphQLEndpoint(globals.prismicRepoName),
      {
        fetch: prismicClient.graphQLFetch,
        method: "GET",
      }
    );

on the line fetch: prismicClient.graphQLFetch, I get the following TS error:
image

Additional Details for graphql types
The data I receive from graphql (compared to what is in the TypeScript types you defined), I get different props, like: On Slice: `items` (for rest API) is `fields` (for graphql) On LinkField: `link_type` (for rest API) is `_linkType` (for graphql) - here even with different content!

To make it work with TypeScript, I would have to extend the types you provide by including the GraphQL props.

Steps to reproduce

  1. Configure prismic client to query on the GraphQL endpoint
  2. Do a query which returns a slice and containing, for example, a LinkField
  3. Note that the response from graphql contains "fields" prop for the slice, and _linkType for the LinkField

What is expected?

  • Types for objects returned from the GraphQL endpoint are provided
  • prismicClient.graphQLFetch returns the same type as requested by GraphQLClient

What is actually happening?

Actually, the types are only returning the props that we receive through the Rest API. And since props are different than the ones returned by GraphQL, they are then missing.

@lausav1 lausav1 added the bug Something isn't working label Sep 27, 2023
@github-actions
Copy link

This issue has been labeled as a bug since it was created using the 🚨 Bug Report Template.

Hi there, thank you so much for the report!

Following our Maintenance Process, we will review your bug report and get back to you next Wednesday. To ensure a smooth review of your issue and avoid unnecessary delays, please make sure your issue includes the following:

  • Information about your environment and packages you use (Node.js version, package names and their versions, etc.)
    Feel free to attach a copy of your package.json file.
  • Any troubleshooting steps you already went through
  • A minimal reproduction of the issue, and/or instructions on how to reproduce it

If you have identified the cause of the bug described in your report and know how to fix it, you're more than welcome to open a pull request addressing it. Check out our quick start guide for a simple contribution process.

If you think your issue is a question (not a bug) and would like quicker support, please close this issue and forward it to an appropriate section on our community forum: https://community.prismic.io

- The Prismic Open-Source Team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant