Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 9af79fc

Browse files
Sean Hoseanho96
andauthored
package: generate graphql types on demand (#2735)
Co-authored-by: Sean Ho <[email protected]>
1 parent 9eefe37 commit 9af79fc

File tree

11 files changed

+10187
-42761
lines changed

11 files changed

+10187
-42761
lines changed

codegen.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
overwrite: true
2+
schema: http://localhost:8000/___graphql
3+
documents:
4+
- ./src/**/*.{ts,tsx}
5+
- ./src/components/graphql/*
6+
generates:
7+
./src/types/graphql.types.ts:
8+
plugins:
9+
- typescript
10+
- typescript-operations
11+
config:
12+
avoidOptionals: true
13+
maybeValue: 'T'
14+
namingConvention:
15+
enumValues: 'keep'
16+
# Uncomment to reformat types with prettier.
17+
# hooks:
18+
# afterOneFileWrite:
19+
# - prettier --write

gatsby-config.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,5 @@ module.exports = {
225225
},
226226
},
227227
'gatsby-plugin-use-query-params',
228-
{
229-
resolve: `gatsby-plugin-graphql-codegen`,
230-
options: {
231-
fileName: `types/graphql.types.ts`,
232-
documentPaths: [
233-
'./src/**/*.{ts,tsx}',
234-
'./src/components/graphql/*',
235-
'./node_modules/gatsby-*/**/*.js',
236-
],
237-
},
238-
},
239228
],
240229
}

package-lock.json

Lines changed: 1757 additions & 37193 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
"webpack": "^5.65.0"
5454
},
5555
"devDependencies": {
56+
"@graphql-codegen/cli": "^2.6.2",
57+
"@graphql-codegen/typescript": "^2.4.5",
58+
"@graphql-codegen/typescript-operations": "^2.3.2",
5659
"@storybook/addon-actions": "^6.4.9",
5760
"@storybook/addon-essentials": "^6.4.9",
5861
"@storybook/addon-links": "^6.4.9",
@@ -73,7 +76,6 @@
7376
"eslint-plugin-react": "^7.28.0",
7477
"eslint-webpack-plugin": "^3.1.1",
7578
"gatsby-plugin-eslint": "^4.0.2",
76-
"gatsby-plugin-graphql-codegen": "^3.1.1",
7779
"gatsby-plugin-styled-components": "^5.4.0",
7880
"gh-pages": "^3.2.3",
7981
"husky": "^7.0.4",
@@ -115,7 +117,9 @@
115117
"pre-commit-lint": "lint-staged",
116118
"type-check": "tsc --noEmit",
117119
"storybook": "start-storybook -p 6006",
118-
"build:storybook": "build-storybook -c .storybook -o public/storybook"
120+
"build:storybook": "build-storybook -c .storybook -o public/storybook",
121+
"codegen": "graphql-codegen --config codegen.yml",
122+
"codegen:watch": "graphql-codegen --config codegen.yml --watch"
119123
},
120124
"repository": {
121125
"type": "git",

src/pages/academy/blog/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react'
22
import styled from 'styled-components'
33
import { graphql } from 'gatsby'
4-
import { AllArticlesQuery } from '../../../../types/graphql.types'
54
import Subscribe from '../components/_subscribe'
65
import AllArticles from './_all-articles'
6+
import { AllArticlesQuery } from 'types/graphql.types'
77
import Layout from 'components/layout/layout'
88
import { SEO, Container, Flex } from 'components/containers'
99
import { Header } from 'components/elements'

src/pages/academy/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react'
22
import { graphql } from 'gatsby'
33
import styled from 'styled-components'
4-
import { AcademyIndexFragment } from '../../../types/graphql.types'
54
import Subscribe from './components/_subscribe'
65
import RecentFeaturedPosts from './_recent-featured-posts'
76
import VideoBanner from './_video-banner'
87
import Hero from './components/_hero'
98
import MarketNews from './components/_market-news'
9+
import { AcademyIndexFragment } from 'types/graphql.types'
1010
import Layout from 'components/layout/layout'
1111
import { Container, SEO, Flex } from 'components/containers'
1212
import { localize, WithIntl } from 'components/localization'

src/pages/academy/videos/_all-videos.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { useEffect, useState } from 'react'
22
import { StyledImg, Container, VideoGrid } from '../common/_styles'
33
import VideoPlayer from '../components/_video-player'
4-
import { DirectusData_Videos } from '../../../../types/graphql.types'
54
import VideoCard from './_video-card'
65
import { VideoDataType } from './index'
6+
import { DirectusData_Videos } from 'types/graphql.types'
77
import { Flex } from 'components/containers'
88
import { cms_assets_end_point } from 'common/constants'
99
import { slugify, removeSpecialCharacterUrl, queryParams } from 'common/utility'

src/pages/academy/videos/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react'
22
import styled from 'styled-components'
33
import { graphql } from 'gatsby'
4-
import { AllVideosQuery } from '../../../../types/graphql.types'
54
import Subscribe from '../components/_subscribe'
65
import AllVideos from './_all-videos'
6+
import { AllVideosQuery } from 'types/graphql.types'
77
import Layout from 'components/layout/layout'
88
import { SEO, Container, Flex } from 'components/containers'
99
import { Header } from 'components/elements'

src/templates/article.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useEffect, useState, useRef } from 'react'
22
import { graphql } from 'gatsby'
3-
import { ArticleQuery } from '../../types/graphql.types'
43
import {
54
ArticleTitle,
65
Background,
@@ -31,6 +30,7 @@ import {
3130
import Banner from '../pages/academy/components/_banner'
3231
import SideSubscriptionBanner from '../pages/academy/components/_side-subscription-banner'
3332
import SocialSharing from '../pages/academy/components/_social-sharing'
33+
import { ArticleQuery } from 'types/graphql.types'
3434
import { localize, WithIntl } from 'components/localization'
3535
import Layout from 'components/layout/layout'
3636
import { SEO, Show, Box, Flex, SectionContainer } from 'components/containers'

0 commit comments

Comments
 (0)