Skip to content

Example using apollo codegen to use dynamic fragments #1

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KATT
Copy link

@KATT KATT commented Jun 10, 2019

You don't have to merge this or anything. I saw your Medium post, I just thought I'd show that you can do dynamically typechecked fragments based on your GraphQL-queries.

This way, the typecheck will fail if you try to use a property we omitted in the actual fragment in the GraphQL-query.

Just not sure if you're aware or not :)

@@ -1,7 +1,7 @@
import gql from 'graphql-tag';

export const QUERY_LAUNCH_LIST = gql`
query LaunchList {
query LaunchListQuery {
launches {
flight_number
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run yarn start then try to remove this line with flight_number for instance and TypeScript starts complaining

Failed to compile.

/Users/alex/dev/graphql-react-typescript-spacex/src/components/LaunchList/LaunchList.tsx
TypeScript error: Property 'flight_number' does not exist on type 'LaunchListQuery_launches'.  TS2339

    24 |                 key={i}
    25 |                 className={`${className}__item`}
  > 26 |                 onClick={() => handleIdChange(launch.flight_number!)}
       |                                                      ^
    27 |               >
    28 |                 {launch.mission_name} ({launch.launch_year})
    29 |               </li>

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

Successfully merging this pull request may close these issues.

1 participant