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.

Create a rule to flag prop types consumed from .graphql files

See original GitHub issue

We 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:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ismail-syedcommented, Mar 30, 2020

I would say it’s still relevant.

0reactions
stale[bot]commented, Sep 12, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

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