Create a rule to flag prop types consumed from .graphql files
See original GitHub issueWe have this best practice documented here, https://github.com/Shopify/web-foundation/blob/master/handbook/Best practices/GraphQL/README.md#organizing-graphql-documents
We should make it harder to break this practice by introducing a lint rule
GraphQL files are the private responsibility of a single component. Components should not reach into another component to grab its GraphQL query for any reason. This is usually done to gain access to individual types from the query when declaring a subcomponent’s prop types. Instead of doing this, you should declare a “dumb” version of the types your component expects, and rely on TypeScript to verify that the parent is passing in the right data:
// bad
import {ComponentQueryData} from '../Parent/graphql/ComponentQuery.graphql';
interface Props {
products: ComponentQueryData.ProductsEdgesNode[];
}
// good
interface Product {
id: string;
title: string;
}
interface Props {
products: Product[];
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Create a rule to flag prop types consumed from .graphql files
Good point. In this example, it seems like those rules would flag this. Assuming those two rules are satisfied, I think we'll still...
Read more >Read from Redux, declare PropTypes, and filter data with ...
As you may recall, writing a GraphQL schema on the server requires you to declare a set of types with fields and resolvers....
Read more >GraphQL API style guide - GitLab Documentation
We have a custom scalar type ( Types::GlobalIDType ) which should be used as the type of input and output arguments when the...
Read more >Spring for GraphQL Documentation
Spring for GraphQL provides support for Spring applications built on GraphQL Java. It is a joint collaboration between the GraphQL Java team ...
Read more >Next js + GraphQL + TypeScript Setup - DEV Community
This article will walk you through a simple GraphQL setup for your Next JS app. This guide is aimed at people already familiar...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would say it’s still relevant.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.