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

fix(gatsby-plugin-graphql): Export schema types #916

Merged
merged 2 commits into from
Aug 24, 2021
Merged

Conversation

tlgimenes
Copy link
Contributor

@tlgimenes tlgimenes commented Aug 23, 2021

What's the purpose of this pull request?

Gatsby plugin graphql currently exports types for each query you do. If you, for inistance, add a query like:

gql`
query GetProductList($selectedFacets: SelectedFacets!) {
  products (selectedFacets: $selectedFacets) {
     productId
  }
}
`

This would generate a typings file like

export type GetProductListQuery = {
  products {
     productId: string
  }
}

export type GetProductListQueryVariables = {
  selectedFacets: SelectedFacets
}

As you can see, the type SelectedFacets was not defined on the typings. This is because the library I'm using expect that we generate these typings alongside another file of the graphql's schema, where this SelectedFacets input type would be defined.

This PR adds just that. It outputs a new file on the path src/typings/schema.graphql.d.ts . This is a global definition file that typescript can read and reason about.

If you don't want it to output the file over this path, you can use the new param of this plugin called schemaPath like:

// gatsby-config.js
module.exports = {
   plugins: [
   {
        resolve: '@vtex/gatsby-plugin-graphql',
        options: {
            schemaPath: 'my-path.d.ts'
        }
   }
   ]
}

How to test it?

vtex-sites/base.store#12
https://github.com/vtex-sites/btglobal.store/pull/807
https://github.com/vtex-sites/marinbrasil.store/pull/619

@tlgimenes tlgimenes requested a review from a team as a code owner August 23, 2021 20:12
@netlify
Copy link

netlify bot commented Aug 23, 2021

✔️ Deploy Preview for storeui ready!

🔨 Explore the source changes: aee0fba

🔍 Inspect the deploy log: https://app.netlify.com/sites/storeui/deploys/61243b1653c2190007fb4c6b

😎 Browse the preview: https://deploy-preview-916--storeui.netlify.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 23, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit aee0fba:

Sandbox Source
Store UI Typescript Configuration

Copy link
Member

@emersonlaurentino emersonlaurentino left a comment

Choose a reason for hiding this comment

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

This is amazing!

@emersonlaurentino
Copy link
Member

@tlgimenes looking at the PRs, it looks like the file is much larger than the sum of all the old ones. Wouldn't it be possible to make it smaller?

@tlgimenes
Copy link
Contributor Author

@tlgimenes looking at the PRs, it looks like the file is much larger than the sum of all the old ones. Wouldn't it be possible to make it smaller?

I'm not sure, since this is the typings of the whole graphql layer. However, what's the intent with this? I don't see a problem, since it's a d.ts file that is not used for the final bundle

@tlgimenes tlgimenes merged commit 65d43d3 into master Aug 24, 2021
@tlgimenes tlgimenes deleted the feat/graphql-types branch August 24, 2021 13:03
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.

2 participants