question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support usage with GraphQL query responses

See original GitHub issue

When using this library to add type information to the anticipated structure of GraphQL queries to Contentful, I found that this library doesn’t quite support my use case.

There are two exported interfaces for each of the Contentful models. The IModelNameFields and IModelName interfaces. When I query with GraphQL, the model of the data is comprised entirely of interfaces matching the IModelNameFields signatures, rather than the IModelName interfaces. For modes that don’t have any references, this is fine because I can simply declare that the GraphQL query structure will contain interfaces using IModelNameFields. However, if there is a relation where one model references another, the reference points to an IModelName interface.

For example, say you have a model Blog with a relation to a Comment model. If I do a GraphQL query for all Comments, then I’m okay because I can use the ICommentFields interface. However, if I do a GraphQL query for Blogs, and I provide the IBlogFields interface, the interface will have a relation to IComment, which won’t match the structure of the object I get back from GraphQL.

Might it be possible for this library to support my use case? As it stands now, I will need to override all of the relations for my models in the generated interfaces. This is significantly less work than maintaining entire interfaces myself, but I’d prefer for the interfaces generated to match 1:1.

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
davidhousedevcommented, Jul 30, 2022

@sonia-y we’ve since migrated to use graphql-code-generator too and I really like that everything is nullable because of preview environments. We found that we were encountering many type errors in preview environments (where validation hasn’t run yet). I suppose if you only read published data and you require everything, the utility is lower 😃.

0reactions
sonia-ycommented, Jul 28, 2022

Actually facing a similar issue… originally was using graphql-code-generator to generate all of the contentful types, but the issue with Contentful’s GraphQL schema is that all fields are nullable/optional, which doesn’t allow us to really leverage TS very well since we need to do null-checks everywhere.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL query best practices
Query only the data you need, where you need it ... One of GraphQL's biggest advantages over a traditional REST API is its...
Read more >
GraphQL Best Practices
A query language for your API — GraphQL provides a complete description of the data in your API, gives clients the power to...
Read more >
Requests and Responses - GraphQL
GraphQL requests can be sent via HTTP POST or HTTP GET requests. ... GET requests must be sent in the following format. The...
Read more >
GraphQL Queries to fetch data
In GraphQL, you fetch data with the help of queries. A query is a GraphQL Operation that allows you to retrieve specific data...
Read more >
GraphQL - Query
GraphQL queries help to reduce over fetching of data. Unlike a Restful API, GraphQL allows a user to restrict fields that should be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found