├── .editorconfig ├── .eslintrc.js ├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── main.yml ├── .gitignore ├── .prettierignore ├── .prettierrc.json ├── .vscode ├── extensions.json ├── launch.json └── settings.json ├── LICENSE ├── README.md ├── dev-test ├── .env ├── codegen.yml ├── githunt │ ├── __generated__ │ │ ├── comment-added.subscription.stencil-component.tsx │ │ ├── comment.query.stencil-component.tsx │ │ ├── comments-page-comment.fragment.stencil-component.tsx │ │ ├── current-user.query.stencil-component.tsx │ │ ├── feed-entry.fragment.stencil-component.tsx │ │ ├── feed.query.stencil-component.tsx │ │ ├── new-entry.mutation.stencil-component.tsx │ │ ├── repo-info.fragment.stencil-component.tsx │ │ ├── submit-comment.mutation.stencil-component.tsx │ │ ├── vote-buttons.fragment.stencil-component.tsx │ │ └── vote.mutation.stencil-component.tsx │ ├── comment-added.subscription.graphql │ ├── comment.query.graphql │ ├── comments-page-comment.fragment.graphql │ ├── current-user.query.graphql │ ├── feed-entry.fragment.graphql │ ├── feed.query.graphql │ ├── flow.flow.js │ ├── graphql-declared-modules.d.ts │ ├── new-entry.mutation.graphql │ ├── repo-info.fragment.graphql │ ├── schema.js │ ├── schema.json │ ├── submit-comment.mutation.graphql │ ├── typed-document-nodes.ts │ ├── types.apolloAngular.sdk.ts │ ├── types.apolloAngular.ts │ ├── types.avoidOptionals.ts │ ├── types.d.ts │ ├── types.enumsAsTypes.ts │ ├── types.flatten.preResolveTypes.ts │ ├── types.immutableTypes.ts │ ├── types.preResolveTypes.compatibility.ts │ ├── types.preResolveTypes.onlyOperationTypes.ts │ ├── types.preResolveTypes.ts │ ├── types.reactApollo.customSuffix.tsx │ ├── types.reactApollo.hooks.tsx │ ├── types.reactApollo.preResolveTypes.tsx │ ├── types.reactApollo.tsx │ ├── types.reactApollo.v2.tsx │ ├── types.stencilApollo.tsx │ ├── types.ts │ ├── types.urql.tsx │ ├── types.vueApollo.ts │ ├── vote-buttons.fragment.graphql │ └── vote.mutation.graphql ├── setup.js ├── test-message │ ├── documents.ts │ ├── schema.graphql │ └── types.tsx ├── test-schema │ ├── env.types.ts │ ├── flow-types.flow.js │ ├── local │ │ ├── schema-ast.js │ │ ├── schema-formats.js │ │ ├── schema-object.js │ │ ├── schema-text.js │ │ └── schema.graphql │ ├── resolvers-federation.ts │ ├── resolvers-root.ts │ ├── resolvers-types.ts │ ├── schema-ast.js │ ├── schema-federation.graphql │ ├── schema-formats.js │ ├── schema-json.js │ ├── schema-object.js │ ├── schema-text.js │ ├── schema-with-imports.graphql │ ├── schema-with-root.graphql │ ├── schema.graphql │ ├── schema.json │ ├── types.preResolveTypes.onlyOperationTypes.ts │ ├── types.preResolveTypes.ts │ ├── typings.avoidOptionals.ts │ ├── typings.enum.ts │ ├── typings.immutableTypes.ts │ ├── typings.ts │ └── typings.wrapped.ts └── tsconfig.json ├── jest.config.js ├── package.json ├── renovate.json ├── src ├── config.ts ├── index.ts └── visitor.ts ├── tests ├── outputs │ ├── autogenSWRKey.ts │ ├── excludeQueries.ts │ ├── infinite.ts │ ├── mutations.ts │ ├── rawRequest.ts │ └── straight.ts ├── swr.spec.ts └── visitor.spec.ts ├── tsconfig.json ├── tsconfig.main.json ├── tsconfig.module.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { es6: true }, 4 | ignorePatterns: ['node_modules', 'build', 'coverage', 'tests/outputs'], 5 | globals: { BigInt: true, console: true, WebAssembly: true }, 6 | overrides: [ 7 | { 8 | files: ['**/*.ts', '**/*.tsx'], 9 | extends: [ 10 | 'airbnb-base', 11 | 'airbnb-typescript/base', 12 | 'airbnb/hooks', 13 | 'plugin:@typescript-eslint/recommended', 14 | 'plugin:import/recommended', 15 | 'plugin:import/typescript', 16 | 'prettier', 17 | ], 18 | parserOptions: { 19 | tsconfigRootDir: __dirname, 20 | project: './tsconfig.json', 21 | }, 22 | rules: { 23 | 'no-underscore-dangle': [ 24 | 'error', 25 | { 26 | allowAfterThis: true, 27 | allowAfterSuper: true, 28 | allowAfterThisConstructor: true, 29 | }, 30 | ], 31 | 'no-restricted-imports': 'off', 32 | '@typescript-eslint/no-explicit-any': 'off', 33 | '@typescript-eslint/explicit-module-boundary-types': 'off', 34 | }, 35 | settings: { 36 | 'import/parsers': { 37 | '@typescript-eslint/parser': ['.ts', '.tsx'], 38 | }, 39 | 'import/resolver': { 40 | typescript: { 41 | project: './tsconfig.json', 42 | }, 43 | node: { 44 | extensions: ['.js', '.ts', '.jsx', '.tsx', '.json'], 45 | }, 46 | }, 47 | }, 48 | }, 49 | { 50 | files: ['./src/lib/**/*.ts'], 51 | rules: { 52 | 'import/prefer-default-export': 'off', 53 | }, 54 | }, 55 | { 56 | files: ['./tests/**/*.ts'], 57 | rules: { 58 | '@typescript-eslint/no-var-requires': 'off', 59 | 'global-require': 'off', 60 | }, 61 | }, 62 | ], 63 | } 64 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Example Contributing Guidelines 2 | 3 | This is an example of GitHub's contributing guidelines file. Check out GitHub's [CONTRIBUTING.md help center article](https://help.github.com/articles/setting-guidelines-for-repository-contributors/) for more information. 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | - **I'm submitting a ...** 2 | [ ] bug report 3 | [ ] feature request 4 | [ ] question about the decisions made in the repository 5 | [ ] question about how to use this project 6 | 7 | - **Summary** 8 | 9 | - **Other information** (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.) 10 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | - **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...) 2 | 3 | - **What is the current behavior?** (You can also link to an open issue here) 4 | 5 | - **What is the new behavior (if this is a feature change)?** 6 | 7 | - **Other information**: 8 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | 13 | strategy: 14 | matrix: 15 | node-version: ['16', '18', '20'] 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: Run tests with ${{ matrix.node-version }} 20 | uses: actions/setup-node@v3 21 | with: 22 | node-version: ${{ matrix.node-version }} 23 | - name: yarn install, and test 24 | run: | 25 | yarn install --pure-lockfile 26 | yarn test 27 | env: 28 | CI: true 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | build 3 | node_modules 4 | test 5 | src/**.js 6 | coverage 7 | *.log 8 | package-lock.json 9 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # package.json is formatted by package managers, so we ignore it here 2 | package.json 3 | tests/outputs/*.ts 4 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true 4 | } 5 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "editorconfig.editorconfig", 4 | "esbenp.prettier-vscode", 5 | "dbaeumer.vscode-eslint", 6 | "mgmcdermott.vscode-language-babel" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | // To debug, make sure a *.spec.ts file is active in the editor, then run a configuration 5 | { 6 | "type": "node", 7 | "request": "launch", 8 | "name": "Debug Active Spec", 9 | "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava", 10 | "runtimeArgs": ["debug", "--break", "--serial", "${file}"], 11 | "port": 9229, 12 | "outputCapture": "std", 13 | "skipFiles": ["/**/*.js"], 14 | "preLaunchTask": "npm: build" 15 | // "smartStep": true 16 | }, 17 | { 18 | // Use this one if you're already running `yarn watch` 19 | "type": "node", 20 | "request": "launch", 21 | "name": "Debug Active Spec (no build)", 22 | "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava", 23 | "runtimeArgs": ["debug", "--break", "--serial", "${file}"], 24 | "port": 9229, 25 | "outputCapture": "std", 26 | "skipFiles": ["/**/*.js"] 27 | // "smartStep": true 28 | }] 29 | } 30 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "css.validate": false, 3 | "editor.codeActionsOnSave": { 4 | "source.fixAll.eslint": true, 5 | "source.fixAll.stylelint": true 6 | }, 7 | "editor.formatOnSave": true, 8 | "editor.defaultFormatter": "esbenp.prettier-vscode", 9 | "html.format.enable": false, 10 | "javascript.format.enable": false, 11 | "json.format.enable": false, 12 | "scss.validate": false, 13 | "typescript.format.enable": false, 14 | "[html]": { 15 | "editor.defaultFormatter": "esbenp.prettier-vscode" 16 | }, 17 | "[css]": { 18 | "editor.defaultFormatter": "esbenp.prettier-vscode" 19 | }, 20 | "[scss]": { 21 | "editor.defaultFormatter": "esbenp.prettier-vscode" 22 | }, 23 | "[sass]": { 24 | "editor.defaultFormatter": "esbenp.prettier-vscode" 25 | }, 26 | "[json]": { 27 | "editor.defaultFormatter": "esbenp.prettier-vscode" 28 | }, 29 | "[javascript]": { 30 | "editor.defaultFormatter": "esbenp.prettier-vscode" 31 | }, 32 | "[javascriptreact]": { 33 | "editor.defaultFormatter": "esbenp.prettier-vscode" 34 | }, 35 | "[typescript]": { 36 | "editor.defaultFormatter": "esbenp.prettier-vscode" 37 | }, 38 | "[typescriptreact]": { 39 | "editor.defaultFormatter": "esbenp.prettier-vscode" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 @croutonn 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # graphql-codegen-plugin-typescript-swr 2 | 3 | A [GraphQL code generator](https://graphql-code-generator.com/) plug-in that automatically generates utility functions for [SWR](https://swr.vercel.app/). 4 | 5 | ## Table of Contents 6 | 7 | - [API Reference](#api-reference) 8 | - [`excludeQueries`](#excludequeries) 9 | - [`useSWRInfinite`](#useswrinfinite) 10 | - [`autogenSWRKey`](#autogenswrkey) 11 | - [Config Example](#config-example) 12 | - [Usage Examples](#usage-examples) 13 | - [Pagination](#pagination) 14 | - [Authorization](#authorization) 15 | - [Next.js](#nextjs) 16 | 17 | ## API Reference 18 | 19 | ### `excludeQueries` 20 | 21 | type: `string | string[]` default: `""` 22 | 23 | Exclude queries that are matched by micromatch (case-sensitive). 24 | 25 | ### `useSWRInfinite` 26 | 27 | type: `string | string[]` default: `""` 28 | 29 | Add `useSWRInfinite()` wrapper for the queries that are matched by micromatch (case-sensitive). 30 | 31 | ### `autogenSWRKey` 32 | 33 | type: `boolean` default: `false` 34 | 35 | Generate key to use `useSWR()` automatically. 36 | But, ​the cache may not work unless you separate the variables object into an external file and use it, or use a primitive type for the value of each field. 37 | 38 | ## Config Example 39 | 40 | ```yaml 41 | generates: 42 | path/to/graphql.ts: 43 | schema: 'schemas/github.graphql' 44 | documents: 'src/services/github/**/*.graphql' 45 | plugins: 46 | - typescript 47 | - typescript-operations 48 | # Put `plugin-typescript-swr` below `typescript-graphql-request` 49 | - typescript-graphql-request 50 | - plugin-typescript-swr 51 | config: 52 | rawRequest: false 53 | excludeQueries: 54 | - foo* 55 | - bar 56 | useSWRInfinite: 57 | - hoge 58 | - bar{1,3} 59 | autogenSWRKey: true 60 | ``` 61 | 62 | ## Usage Examples 63 | 64 | For the given input: 65 | 66 | ```graphql 67 | query continents { 68 | continents { 69 | name 70 | countries { 71 | ...CountryFields 72 | } 73 | } 74 | } 75 | 76 | fragment CountryFields on Country { 77 | name 78 | currency 79 | } 80 | ``` 81 | 82 | It generates SDK you can import and wrap your GraphQLClient instance, and get fully-typed SDK based on your operations: 83 | 84 | ```tsx 85 | import { GraphQLClient } from 'graphql-request' 86 | import { getSdkWithHooks } from './sdk' 87 | 88 | function Continents() { 89 | const client = new GraphQLClient('https://countries.trevorblades.com/') 90 | const sdk = getSdkWithHooks(client) 91 | 92 | const { data, error } = sdk.useContinents('Continents') 93 | 94 | if (error) return
failed to load
95 | if (!data) return
loading...
96 | 97 | return ( 98 | 103 | ) 104 | } 105 | ``` 106 | 107 | ### Pagination 108 | 109 | #### codegen.yaml 110 | 111 | ```yaml 112 | config: 113 | useSWRInfinite: 114 | - MyQuery 115 | ``` 116 | 117 | #### Functional Component 118 | 119 | ```tsx 120 | const { data, size, setSize } = sdk.useMyQueryInfinite( 121 | 'id_for_caching', 122 | (pageIndex, previousPageData) => { 123 | if (previousPageData && !previousPageData.search.pageInfo.hasNextPage) 124 | return null 125 | return [ 126 | 'after', 127 | previousPageData ? previousPageData.search.pageInfo.endCursor : null, 128 | ] 129 | }, 130 | variables, // GraphQL Query Variables 131 | config // Configuration of useSWRInfinite 132 | ) 133 | ``` 134 | 135 | ### Authorization 136 | 137 | ```typescript 138 | import { GraphQLClient } from 'graphql-request' 139 | import { getSdkWithHooks } from './sdk' 140 | import { getJwt } from './jwt' 141 | 142 | const getAuthorizedSdk = () => { 143 | const headers: Record = { 'Content-Type': 'application/json' } 144 | const jwt = getJwt() 145 | if (jwt) { 146 | headers.Authorization = `Bearer ${jwt}` 147 | } 148 | return getSdkWithHooks( 149 | new GraphQLClient(`${process.env.NEXT_PUBLIC_API_URL}`, { 150 | headers, 151 | }) 152 | ) 153 | } 154 | 155 | export default getAuthorizedSdk 156 | ``` 157 | 158 | ### Next.js 159 | 160 | ```tsx 161 | // pages/posts/[slug].tsx 162 | import { GetStaticProps, NextPage } from 'next' 163 | import ErrorPage from 'next/error' 164 | import { useRouter } from 'next/router' 165 | import Article from '../components/Article' 166 | import sdk from '../sdk' 167 | import { GetArticleQuery } from '../graphql' 168 | 169 | type StaticParams = { slug: string } 170 | type StaticProps = StaticParams & { 171 | initialData: { 172 | articleBySlug: NonNullable 173 | } 174 | } 175 | type ArticlePageProps = StaticProps & { preview?: boolean } 176 | 177 | export const getStaticProps: GetStaticProps = async ({ 178 | params, 179 | preview = false, 180 | previewData 181 | }) => { 182 | if (!params) { 183 | throw new Error('Parameter is invalid!') 184 | } 185 | 186 | const { articleBySlug: article } = await sdk().GetArticle({ 187 | slug: params.slug, 188 | }) 189 | 190 | if (!article) { 191 | throw new Error('Article is not found!') 192 | } 193 | 194 | const props: ArticlePageProps = { 195 | slug: params.slug, 196 | preview, 197 | initialData: { 198 | articleBySlug: article 199 | } 200 | } 201 | 202 | return { 203 | props: preview 204 | ? { 205 | ...props, 206 | ...previewData, 207 | } 208 | : props, 209 | } 210 | }) 211 | 212 | export const ArticlePage: NextPage = ({ slug, initialData, preview }) => { 213 | const router = useRouter() 214 | const { data: { article }, mutate: mutateArticle } = sdk().useGetArticle( 215 | `GetArticle/${slug}`, { slug }, { initialData } 216 | ) 217 | 218 | if (!router.isFallback && !article) { 219 | return 220 | } 221 | 222 | // because of typescript problem 223 | if (!article) { 224 | throw new Error('Article is not found!') 225 | } 226 | 227 | return ( 228 | 229 | <> 230 | 231 | {article.title} 232 | 233 |
234 | 235 | 236 | ) 237 | } 238 | ``` 239 | -------------------------------------------------------------------------------- /dev-test/.env: -------------------------------------------------------------------------------- 1 | SCHEMA_PATH = ./dev-test/test-schema/schema.graphql -------------------------------------------------------------------------------- /dev-test/githunt/__generated__/comment-added.subscription.stencil-component.tsx: -------------------------------------------------------------------------------- 1 | import gql from 'graphql-tag'; 2 | import 'stencil-apollo'; 3 | import { Component, Prop, h } from '@stencil/core'; 4 | 5 | declare global { 6 | export type OnCommentAddedSubscriptionVariables = Types.Exact<{ 7 | repoFullName: Types.Scalars['String']; 8 | }>; 9 | 10 | export type OnCommentAddedSubscription = { __typename?: 'Subscription' } & { 11 | commentAdded?: Types.Maybe< 12 | { __typename?: 'Comment' } & Pick & { 13 | postedBy: { __typename?: 'User' } & Pick; 14 | } 15 | >; 16 | }; 17 | } 18 | 19 | const OnCommentAddedDocument = gql` 20 | subscription onCommentAdded($repoFullName: String!) { 21 | commentAdded(repoFullName: $repoFullName) { 22 | id 23 | postedBy { 24 | login 25 | html_url 26 | } 27 | createdAt 28 | content 29 | } 30 | } 31 | `; 32 | 33 | @Component({ 34 | tag: 'apollo-on-comment-added', 35 | }) 36 | export class OnCommentAddedComponent { 37 | @Prop() renderer: import('stencil-apollo').SubscriptionRenderer< 38 | OnCommentAddedSubscription, 39 | OnCommentAddedSubscriptionVariables 40 | >; 41 | @Prop() variables: OnCommentAddedSubscriptionVariables; 42 | render() { 43 | return ( 44 | 45 | ); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /dev-test/githunt/__generated__/comment.query.stencil-component.tsx: -------------------------------------------------------------------------------- 1 | import gql from 'graphql-tag'; 2 | import { CommentsPageCommentFragmentDoc } from './comments-page-comment.fragment.stencil-component'; 3 | import 'stencil-apollo'; 4 | import { Component, Prop, h } from '@stencil/core'; 5 | 6 | declare global { 7 | export type CommentQueryVariables = Types.Exact<{ 8 | repoFullName: Types.Scalars['String']; 9 | limit?: Types.Maybe; 10 | offset?: Types.Maybe; 11 | }>; 12 | 13 | export type CommentQuery = { __typename?: 'Query' } & { 14 | currentUser?: Types.Maybe<{ __typename?: 'User' } & Pick>; 15 | entry?: Types.Maybe< 16 | { __typename?: 'Entry' } & Pick & { 17 | postedBy: { __typename?: 'User' } & Pick; 18 | comments: Array>; 19 | repository: { __typename?: 'Repository' } & Pick< 20 | Types.Repository, 21 | 'description' | 'open_issues_count' | 'stargazers_count' | 'full_name' | 'html_url' 22 | >; 23 | } 24 | >; 25 | }; 26 | } 27 | 28 | const CommentDocument = gql` 29 | query Comment($repoFullName: String!, $limit: Int, $offset: Int) { 30 | currentUser { 31 | login 32 | html_url 33 | } 34 | entry(repoFullName: $repoFullName) { 35 | id 36 | postedBy { 37 | login 38 | html_url 39 | } 40 | createdAt 41 | comments(limit: $limit, offset: $offset) { 42 | ...CommentsPageComment 43 | } 44 | commentCount 45 | repository { 46 | full_name 47 | html_url 48 | ... on Repository { 49 | description 50 | open_issues_count 51 | stargazers_count 52 | } 53 | } 54 | } 55 | } 56 | ${CommentsPageCommentFragmentDoc} 57 | `; 58 | 59 | @Component({ 60 | tag: 'apollo-comment', 61 | }) 62 | export class CommentComponent { 63 | @Prop() renderer: import('stencil-apollo').QueryRenderer; 64 | @Prop() variables: CommentQueryVariables; 65 | render() { 66 | return ; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /dev-test/githunt/__generated__/comments-page-comment.fragment.stencil-component.tsx: -------------------------------------------------------------------------------- 1 | import gql from 'graphql-tag'; 2 | 3 | declare global { 4 | export type CommentsPageCommentFragment = { __typename?: 'Comment' } & Pick< 5 | Types.Comment, 6 | 'id' | 'createdAt' | 'content' 7 | > & { postedBy: { __typename?: 'User' } & Pick }; 8 | } 9 | 10 | export const CommentsPageCommentFragmentDoc = gql` 11 | fragment CommentsPageComment on Comment { 12 | id 13 | postedBy { 14 | login 15 | html_url 16 | } 17 | createdAt 18 | content 19 | } 20 | `; 21 | -------------------------------------------------------------------------------- /dev-test/githunt/__generated__/current-user.query.stencil-component.tsx: -------------------------------------------------------------------------------- 1 | import gql from 'graphql-tag'; 2 | import 'stencil-apollo'; 3 | import { Component, Prop, h } from '@stencil/core'; 4 | 5 | declare global { 6 | export type CurrentUserForProfileQueryVariables = Types.Exact<{ [key: string]: never }>; 7 | 8 | export type CurrentUserForProfileQuery = { __typename?: 'Query' } & { 9 | currentUser?: Types.Maybe<{ __typename?: 'User' } & Pick>; 10 | }; 11 | } 12 | 13 | const CurrentUserForProfileDocument = gql` 14 | query CurrentUserForProfile { 15 | currentUser { 16 | login 17 | avatar_url 18 | } 19 | } 20 | `; 21 | 22 | @Component({ 23 | tag: 'apollo-current-user-for-profile', 24 | }) 25 | export class CurrentUserForProfileComponent { 26 | @Prop() renderer: import('stencil-apollo').QueryRenderer< 27 | CurrentUserForProfileQuery, 28 | CurrentUserForProfileQueryVariables 29 | >; 30 | @Prop() variables: CurrentUserForProfileQueryVariables; 31 | render() { 32 | return ; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /dev-test/githunt/__generated__/feed-entry.fragment.stencil-component.tsx: -------------------------------------------------------------------------------- 1 | import gql from 'graphql-tag'; 2 | import { VoteButtonsFragmentDoc } from './vote-buttons.fragment.stencil-component'; 3 | import { RepoInfoFragmentDoc } from './repo-info.fragment.stencil-component'; 4 | 5 | declare global { 6 | export type FeedEntryFragment = { __typename?: 'Entry' } & Pick & { 7 | repository: { __typename?: 'Repository' } & Pick & { 8 | owner?: Types.Maybe<{ __typename?: 'User' } & Pick>; 9 | }; 10 | } & VoteButtonsFragment & 11 | RepoInfoFragment; 12 | } 13 | 14 | export const FeedEntryFragmentDoc = gql` 15 | fragment FeedEntry on Entry { 16 | id 17 | commentCount 18 | repository { 19 | full_name 20 | html_url 21 | owner { 22 | avatar_url 23 | } 24 | } 25 | ...VoteButtons 26 | ...RepoInfo 27 | } 28 | ${VoteButtonsFragmentDoc} 29 | ${RepoInfoFragmentDoc} 30 | `; 31 | -------------------------------------------------------------------------------- /dev-test/githunt/__generated__/feed.query.stencil-component.tsx: -------------------------------------------------------------------------------- 1 | import gql from 'graphql-tag'; 2 | import { FeedEntryFragmentDoc } from './feed-entry.fragment.stencil-component'; 3 | import 'stencil-apollo'; 4 | import { Component, Prop, h } from '@stencil/core'; 5 | 6 | declare global { 7 | export type FeedQueryVariables = Types.Exact<{ 8 | type: Types.FeedType; 9 | offset?: Types.Maybe; 10 | limit?: Types.Maybe; 11 | }>; 12 | 13 | export type FeedQuery = { __typename?: 'Query' } & { 14 | currentUser?: Types.Maybe<{ __typename?: 'User' } & Pick>; 15 | feed?: Types.Maybe>>; 16 | }; 17 | } 18 | 19 | const FeedDocument = gql` 20 | query Feed($type: FeedType!, $offset: Int, $limit: Int) { 21 | currentUser { 22 | login 23 | } 24 | feed(type: $type, offset: $offset, limit: $limit) { 25 | ...FeedEntry 26 | } 27 | } 28 | ${FeedEntryFragmentDoc} 29 | `; 30 | 31 | @Component({ 32 | tag: 'apollo-feed', 33 | }) 34 | export class FeedComponent { 35 | @Prop() renderer: import('stencil-apollo').QueryRenderer; 36 | @Prop() variables: FeedQueryVariables; 37 | render() { 38 | return ; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /dev-test/githunt/__generated__/new-entry.mutation.stencil-component.tsx: -------------------------------------------------------------------------------- 1 | import gql from 'graphql-tag'; 2 | import 'stencil-apollo'; 3 | import { Component, Prop, h } from '@stencil/core'; 4 | 5 | declare global { 6 | export type SubmitRepositoryMutationVariables = Types.Exact<{ 7 | repoFullName: Types.Scalars['String']; 8 | }>; 9 | 10 | export type SubmitRepositoryMutation = { __typename?: 'Mutation' } & { 11 | submitRepository?: Types.Maybe<{ __typename?: 'Entry' } & Pick>; 12 | }; 13 | } 14 | 15 | const SubmitRepositoryDocument = gql` 16 | mutation submitRepository($repoFullName: String!) { 17 | submitRepository(repoFullName: $repoFullName) { 18 | createdAt 19 | } 20 | } 21 | `; 22 | 23 | @Component({ 24 | tag: 'apollo-submit-repository', 25 | }) 26 | export class SubmitRepositoryComponent { 27 | @Prop() renderer: import('stencil-apollo').MutationRenderer< 28 | SubmitRepositoryMutation, 29 | SubmitRepositoryMutationVariables 30 | >; 31 | @Prop() variables: SubmitRepositoryMutationVariables; 32 | render() { 33 | return ; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /dev-test/githunt/__generated__/repo-info.fragment.stencil-component.tsx: -------------------------------------------------------------------------------- 1 | import gql from 'graphql-tag'; 2 | 3 | declare global { 4 | export type RepoInfoFragment = { __typename?: 'Entry' } & Pick & { 5 | repository: { __typename?: 'Repository' } & Pick< 6 | Types.Repository, 7 | 'description' | 'stargazers_count' | 'open_issues_count' 8 | >; 9 | postedBy: { __typename?: 'User' } & Pick; 10 | }; 11 | } 12 | 13 | export const RepoInfoFragmentDoc = gql` 14 | fragment RepoInfo on Entry { 15 | createdAt 16 | repository { 17 | description 18 | stargazers_count 19 | open_issues_count 20 | } 21 | postedBy { 22 | html_url 23 | login 24 | } 25 | } 26 | `; 27 | -------------------------------------------------------------------------------- /dev-test/githunt/__generated__/submit-comment.mutation.stencil-component.tsx: -------------------------------------------------------------------------------- 1 | import gql from 'graphql-tag'; 2 | import { CommentsPageCommentFragmentDoc } from './comments-page-comment.fragment.stencil-component'; 3 | import 'stencil-apollo'; 4 | import { Component, Prop, h } from '@stencil/core'; 5 | 6 | declare global { 7 | export type SubmitCommentMutationVariables = Types.Exact<{ 8 | repoFullName: Types.Scalars['String']; 9 | commentContent: Types.Scalars['String']; 10 | }>; 11 | 12 | export type SubmitCommentMutation = { __typename?: 'Mutation' } & { 13 | submitComment?: Types.Maybe<{ __typename?: 'Comment' } & CommentsPageCommentFragment>; 14 | }; 15 | } 16 | 17 | const SubmitCommentDocument = gql` 18 | mutation submitComment($repoFullName: String!, $commentContent: String!) { 19 | submitComment(repoFullName: $repoFullName, commentContent: $commentContent) { 20 | ...CommentsPageComment 21 | } 22 | } 23 | ${CommentsPageCommentFragmentDoc} 24 | `; 25 | 26 | @Component({ 27 | tag: 'apollo-submit-comment', 28 | }) 29 | export class SubmitCommentComponent { 30 | @Prop() renderer: import('stencil-apollo').MutationRenderer; 31 | @Prop() variables: SubmitCommentMutationVariables; 32 | render() { 33 | return ; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /dev-test/githunt/__generated__/vote-buttons.fragment.stencil-component.tsx: -------------------------------------------------------------------------------- 1 | import gql from 'graphql-tag'; 2 | 3 | declare global { 4 | export type VoteButtonsFragment = { __typename?: 'Entry' } & Pick & { 5 | vote: { __typename?: 'Vote' } & Pick; 6 | }; 7 | } 8 | 9 | export const VoteButtonsFragmentDoc = gql` 10 | fragment VoteButtons on Entry { 11 | score 12 | vote { 13 | vote_value 14 | } 15 | } 16 | `; 17 | -------------------------------------------------------------------------------- /dev-test/githunt/__generated__/vote.mutation.stencil-component.tsx: -------------------------------------------------------------------------------- 1 | import gql from 'graphql-tag'; 2 | import 'stencil-apollo'; 3 | import { Component, Prop, h } from '@stencil/core'; 4 | 5 | declare global { 6 | export type VoteMutationVariables = Types.Exact<{ 7 | repoFullName: Types.Scalars['String']; 8 | type: Types.VoteType; 9 | }>; 10 | 11 | export type VoteMutation = { __typename?: 'Mutation' } & { 12 | vote?: Types.Maybe< 13 | { __typename?: 'Entry' } & Pick & { 14 | vote: { __typename?: 'Vote' } & Pick; 15 | } 16 | >; 17 | }; 18 | } 19 | 20 | const VoteDocument = gql` 21 | mutation vote($repoFullName: String!, $type: VoteType!) { 22 | vote(repoFullName: $repoFullName, type: $type) { 23 | score 24 | id 25 | vote { 26 | vote_value 27 | } 28 | } 29 | } 30 | `; 31 | 32 | @Component({ 33 | tag: 'apollo-vote', 34 | }) 35 | export class VoteComponent { 36 | @Prop() renderer: import('stencil-apollo').MutationRenderer; 37 | @Prop() variables: VoteMutationVariables; 38 | render() { 39 | return ; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /dev-test/githunt/comment-added.subscription.graphql: -------------------------------------------------------------------------------- 1 | subscription onCommentAdded($repoFullName: String!) { 2 | commentAdded(repoFullName: $repoFullName) { 3 | id 4 | postedBy { 5 | login 6 | html_url 7 | } 8 | createdAt 9 | content 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /dev-test/githunt/comment.query.graphql: -------------------------------------------------------------------------------- 1 | # import './comments-page-comment.fragment.graphql' 2 | 3 | query Comment($repoFullName: String!, $limit: Int, $offset: Int) { 4 | # Eventually move this into a no fetch query right on the entry 5 | # since we literally just need this info to determine whether to 6 | # show upvote/downvote buttons 7 | currentUser { 8 | login 9 | html_url 10 | } 11 | entry(repoFullName: $repoFullName) { 12 | id 13 | postedBy { 14 | login 15 | html_url 16 | } 17 | createdAt 18 | comments(limit: $limit, offset: $offset) { 19 | ...CommentsPageComment 20 | } 21 | commentCount 22 | repository { 23 | full_name 24 | html_url 25 | 26 | ... on Repository { 27 | description 28 | open_issues_count 29 | stargazers_count 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /dev-test/githunt/comments-page-comment.fragment.graphql: -------------------------------------------------------------------------------- 1 | fragment CommentsPageComment on Comment { 2 | id 3 | postedBy { 4 | login 5 | html_url 6 | } 7 | createdAt 8 | content 9 | } 10 | -------------------------------------------------------------------------------- /dev-test/githunt/current-user.query.graphql: -------------------------------------------------------------------------------- 1 | query CurrentUserForProfile { 2 | currentUser { 3 | login 4 | avatar_url 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /dev-test/githunt/feed-entry.fragment.graphql: -------------------------------------------------------------------------------- 1 | fragment FeedEntry on Entry { 2 | id 3 | commentCount 4 | repository { 5 | full_name 6 | html_url 7 | owner { 8 | avatar_url 9 | } 10 | } 11 | ...VoteButtons 12 | ...RepoInfo 13 | } 14 | -------------------------------------------------------------------------------- /dev-test/githunt/feed.query.graphql: -------------------------------------------------------------------------------- 1 | query Feed($type: FeedType!, $offset: Int, $limit: Int) { 2 | currentUser { 3 | login 4 | } 5 | feed(type: $type, offset: $offset, limit: $limit) { 6 | ...FeedEntry 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /dev-test/githunt/flow.flow.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | 3 | // @flow 4 | 5 | /** All built-in and custom scalars, mapped to their actual values */ 6 | export type Scalars = {| 7 | ID: string, 8 | String: string, 9 | Boolean: boolean, 10 | Int: number, 11 | Float: number, 12 | |}; 13 | 14 | export type Query = {| 15 | __typename?: 'Query', 16 | /** A feed of repository submissions */ 17 | feed?: ?Array, 18 | /** A single entry */ 19 | entry?: ?Entry, 20 | /** Return the currently logged in user, or null if nobody is logged in */ 21 | currentUser?: ?User, 22 | |}; 23 | 24 | export type QueryFeedArgs = {| 25 | type: FeedType, 26 | offset?: ?$ElementType, 27 | limit?: ?$ElementType, 28 | |}; 29 | 30 | export type QueryEntryArgs = {| 31 | repoFullName: $ElementType, 32 | |}; 33 | 34 | export const FeedTypeValues = Object.freeze({ 35 | /** Sort by a combination of freshness and score, using Reddit's algorithm */ 36 | Hot: 'HOT', 37 | /** Newest entries first */ 38 | New: 'NEW', 39 | /** Highest score entries first */ 40 | Top: 'TOP', 41 | }); 42 | 43 | /** A list of options for the sort order of the feed */ 44 | export type FeedType = $Values; 45 | 46 | /** Information about a GitHub repository submitted to GitHunt */ 47 | export type Entry = {| 48 | __typename?: 'Entry', 49 | /** Information about the repository from GitHub */ 50 | repository: Repository, 51 | /** The GitHub user who submitted this entry */ 52 | postedBy: User, 53 | /** A timestamp of when the entry was submitted */ 54 | createdAt: $ElementType, 55 | /** The score of this repository, upvotes - downvotes */ 56 | score: $ElementType, 57 | /** The hot score of this repository */ 58 | hotScore: $ElementType, 59 | /** Comments posted about this repository */ 60 | comments: Array, 61 | /** The number of comments posted about this repository */ 62 | commentCount: $ElementType, 63 | /** The SQL ID of this entry */ 64 | id: $ElementType, 65 | /** XXX to be changed */ 66 | vote: Vote, 67 | |}; 68 | 69 | /** Information about a GitHub repository submitted to GitHunt */ 70 | export type EntryCommentsArgs = {| 71 | limit?: ?$ElementType, 72 | offset?: ?$ElementType, 73 | |}; 74 | 75 | /** 76 | * A repository object from the GitHub API. This uses the exact field names returned by the 77 | * GitHub API for simplicity, even though the convention for GraphQL is usually to camel case. 78 | */ 79 | export type Repository = {| 80 | __typename?: 'Repository', 81 | /** Just the name of the repository, e.g. GitHunt-API */ 82 | name: $ElementType, 83 | /** The full name of the repository with the username, e.g. apollostack/GitHunt-API */ 84 | full_name: $ElementType, 85 | /** The description of the repository */ 86 | description?: ?$ElementType, 87 | /** The link to the repository on GitHub */ 88 | html_url: $ElementType, 89 | /** The number of people who have starred this repository on GitHub */ 90 | stargazers_count: $ElementType, 91 | /** The number of open issues on this repository on GitHub */ 92 | open_issues_count?: ?$ElementType, 93 | /** The owner of this repository on GitHub, e.g. apollostack */ 94 | owner?: ?User, 95 | |}; 96 | 97 | /** A user object from the GitHub API. This uses the exact field names returned from the GitHub API. */ 98 | export type User = {| 99 | __typename?: 'User', 100 | /** The name of the user, e.g. apollostack */ 101 | login: $ElementType, 102 | /** The URL to a directly embeddable image for this user's avatar */ 103 | avatar_url: $ElementType, 104 | /** The URL of this user's GitHub page */ 105 | html_url: $ElementType, 106 | |}; 107 | 108 | /** A comment about an entry, submitted by a user */ 109 | export type Comment = {| 110 | __typename?: 'Comment', 111 | /** The SQL ID of this entry */ 112 | id: $ElementType, 113 | /** The GitHub user who posted the comment */ 114 | postedBy: User, 115 | /** A timestamp of when the comment was posted */ 116 | createdAt: $ElementType, 117 | /** The text of the comment */ 118 | content: $ElementType, 119 | /** The repository which this comment is about */ 120 | repoName: $ElementType, 121 | |}; 122 | 123 | /** XXX to be removed */ 124 | export type Vote = {| 125 | __typename?: 'Vote', 126 | vote_value: $ElementType, 127 | |}; 128 | 129 | export type Mutation = {| 130 | __typename?: 'Mutation', 131 | /** Submit a new repository, returns the new submission */ 132 | submitRepository?: ?Entry, 133 | /** Vote on a repository submission, returns the submission that was voted on */ 134 | vote?: ?Entry, 135 | /** Comment on a repository, returns the new comment */ 136 | submitComment?: ?Comment, 137 | |}; 138 | 139 | export type MutationSubmitRepositoryArgs = {| 140 | repoFullName: $ElementType, 141 | |}; 142 | 143 | export type MutationVoteArgs = {| 144 | repoFullName: $ElementType, 145 | type: VoteType, 146 | |}; 147 | 148 | export type MutationSubmitCommentArgs = {| 149 | repoFullName: $ElementType, 150 | commentContent: $ElementType, 151 | |}; 152 | 153 | export const VoteTypeValues = Object.freeze({ 154 | Up: 'UP', 155 | Down: 'DOWN', 156 | Cancel: 'CANCEL', 157 | }); 158 | 159 | /** The type of vote to record, when submitting a vote */ 160 | export type VoteType = $Values; 161 | 162 | export type Subscription = {| 163 | __typename?: 'Subscription', 164 | /** Subscription fires on every comment added */ 165 | commentAdded?: ?Comment, 166 | |}; 167 | 168 | export type SubscriptionCommentAddedArgs = {| 169 | repoFullName: $ElementType, 170 | |}; 171 | 172 | type $Pick = $ObjMapi(k: Key) => $ElementType>; 173 | 174 | export type OnCommentAddedSubscriptionVariables = { 175 | repoFullName: $ElementType, 176 | }; 177 | 178 | export type OnCommentAddedSubscription = { 179 | ...{ __typename?: 'Subscription' }, 180 | ...{| 181 | commentAdded?: ?{ 182 | ...{ __typename?: 'Comment' }, 183 | ...$Pick, 184 | ...{| 185 | postedBy: { 186 | ...{ __typename?: 'User' }, 187 | ...$Pick, 188 | }, 189 | |}, 190 | }, 191 | |}, 192 | }; 193 | 194 | export type CommentQueryVariables = { 195 | repoFullName: $ElementType, 196 | limit?: ?$ElementType, 197 | offset?: ?$ElementType, 198 | }; 199 | 200 | export type CommentQuery = { 201 | ...{ __typename?: 'Query' }, 202 | ...{| 203 | currentUser?: ?{ 204 | ...{ __typename?: 'User' }, 205 | ...$Pick, 206 | }, 207 | entry?: ?{ 208 | ...{ __typename?: 'Entry' }, 209 | ...$Pick, 210 | ...{| 211 | postedBy: { 212 | ...{ __typename?: 'User' }, 213 | ...$Pick, 214 | }, 215 | comments: Array, 219 | repository: { 220 | ...{ __typename?: 'Repository' }, 221 | ...$Pick< 222 | Repository, 223 | {| description?: *, open_issues_count?: *, stargazers_count: *, full_name: *, html_url: * |} 224 | >, 225 | }, 226 | |}, 227 | }, 228 | |}, 229 | }; 230 | 231 | export type CommentsPageCommentFragment = { 232 | ...{ __typename?: 'Comment' }, 233 | ...$Pick, 234 | ...{| 235 | postedBy: { 236 | ...{ __typename?: 'User' }, 237 | ...$Pick, 238 | }, 239 | |}, 240 | }; 241 | 242 | export type CurrentUserForProfileQueryVariables = {}; 243 | 244 | export type CurrentUserForProfileQuery = { 245 | ...{ __typename?: 'Query' }, 246 | ...{| 247 | currentUser?: ?{ 248 | ...{ __typename?: 'User' }, 249 | ...$Pick, 250 | }, 251 | |}, 252 | }; 253 | 254 | export type FeedEntryFragment = { 255 | ...{ __typename?: 'Entry' }, 256 | ...$Pick, 257 | ...{| 258 | repository: { 259 | ...{ __typename?: 'Repository' }, 260 | ...$Pick, 261 | ...{| 262 | owner?: ?{ 263 | ...{ __typename?: 'User' }, 264 | ...$Pick, 265 | }, 266 | |}, 267 | }, 268 | |}, 269 | ...VoteButtonsFragment, 270 | ...RepoInfoFragment, 271 | }; 272 | 273 | export type FeedQueryVariables = { 274 | type: FeedType, 275 | offset?: ?$ElementType, 276 | limit?: ?$ElementType, 277 | }; 278 | 279 | export type FeedQuery = { 280 | ...{ __typename?: 'Query' }, 281 | ...{| 282 | currentUser?: ?{ 283 | ...{ __typename?: 'User' }, 284 | ...$Pick, 285 | }, 286 | feed?: ?Array, 290 | |}, 291 | }; 292 | 293 | export type SubmitRepositoryMutationVariables = { 294 | repoFullName: $ElementType, 295 | }; 296 | 297 | export type SubmitRepositoryMutation = { 298 | ...{ __typename?: 'Mutation' }, 299 | ...{| 300 | submitRepository?: ?{ 301 | ...{ __typename?: 'Entry' }, 302 | ...$Pick, 303 | }, 304 | |}, 305 | }; 306 | 307 | export type RepoInfoFragment = { 308 | ...{ __typename?: 'Entry' }, 309 | ...$Pick, 310 | ...{| 311 | repository: { 312 | ...{ __typename?: 'Repository' }, 313 | ...$Pick, 314 | }, 315 | postedBy: { 316 | ...{ __typename?: 'User' }, 317 | ...$Pick, 318 | }, 319 | |}, 320 | }; 321 | 322 | export type SubmitCommentMutationVariables = { 323 | repoFullName: $ElementType, 324 | commentContent: $ElementType, 325 | }; 326 | 327 | export type SubmitCommentMutation = { 328 | ...{ __typename?: 'Mutation' }, 329 | ...{| 330 | submitComment?: ?{ 331 | ...{ __typename?: 'Comment' }, 332 | ...CommentsPageCommentFragment, 333 | }, 334 | |}, 335 | }; 336 | 337 | export type VoteButtonsFragment = { 338 | ...{ __typename?: 'Entry' }, 339 | ...$Pick, 340 | ...{| 341 | vote: { 342 | ...{ __typename?: 'Vote' }, 343 | ...$Pick, 344 | }, 345 | |}, 346 | }; 347 | 348 | export type VoteMutationVariables = { 349 | repoFullName: $ElementType, 350 | type: VoteType, 351 | }; 352 | 353 | export type VoteMutation = { 354 | ...{ __typename?: 'Mutation' }, 355 | ...{| 356 | vote?: ?{ 357 | ...{ __typename?: 'Entry' }, 358 | ...$Pick, 359 | ...{| 360 | vote: { 361 | ...{ __typename?: 'Vote' }, 362 | ...$Pick, 363 | }, 364 | |}, 365 | }, 366 | |}, 367 | }; 368 | -------------------------------------------------------------------------------- /dev-test/githunt/graphql-declared-modules.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*/comment-added.subscription.graphql' { 2 | import { DocumentNode } from 'graphql'; 3 | const defaultDocument: DocumentNode; 4 | export const onCommentAdded: DocumentNode; 5 | 6 | export default defaultDocument; 7 | } 8 | 9 | declare module '*/comment.query.graphql' { 10 | import { DocumentNode } from 'graphql'; 11 | const defaultDocument: DocumentNode; 12 | export const Comment: DocumentNode; 13 | 14 | export default defaultDocument; 15 | } 16 | 17 | declare module '*/comments-page-comment.fragment.graphql' { 18 | import { DocumentNode } from 'graphql'; 19 | const defaultDocument: DocumentNode; 20 | export const CommentsPageComment: DocumentNode; 21 | 22 | export default defaultDocument; 23 | } 24 | 25 | declare module '*/current-user.query.graphql' { 26 | import { DocumentNode } from 'graphql'; 27 | const defaultDocument: DocumentNode; 28 | export const CurrentUserForProfile: DocumentNode; 29 | 30 | export default defaultDocument; 31 | } 32 | 33 | declare module '*/feed-entry.fragment.graphql' { 34 | import { DocumentNode } from 'graphql'; 35 | const defaultDocument: DocumentNode; 36 | export const FeedEntry: DocumentNode; 37 | 38 | export default defaultDocument; 39 | } 40 | 41 | declare module '*/feed.query.graphql' { 42 | import { DocumentNode } from 'graphql'; 43 | const defaultDocument: DocumentNode; 44 | export const Feed: DocumentNode; 45 | 46 | export default defaultDocument; 47 | } 48 | 49 | declare module '*/new-entry.mutation.graphql' { 50 | import { DocumentNode } from 'graphql'; 51 | const defaultDocument: DocumentNode; 52 | export const submitRepository: DocumentNode; 53 | 54 | export default defaultDocument; 55 | } 56 | 57 | declare module '*/repo-info.fragment.graphql' { 58 | import { DocumentNode } from 'graphql'; 59 | const defaultDocument: DocumentNode; 60 | export const RepoInfo: DocumentNode; 61 | 62 | export default defaultDocument; 63 | } 64 | 65 | declare module '*/submit-comment.mutation.graphql' { 66 | import { DocumentNode } from 'graphql'; 67 | const defaultDocument: DocumentNode; 68 | export const submitComment: DocumentNode; 69 | 70 | export default defaultDocument; 71 | } 72 | 73 | declare module '*/vote-buttons.fragment.graphql' { 74 | import { DocumentNode } from 'graphql'; 75 | const defaultDocument: DocumentNode; 76 | export const VoteButtons: DocumentNode; 77 | 78 | export default defaultDocument; 79 | } 80 | 81 | declare module '*/vote.mutation.graphql' { 82 | import { DocumentNode } from 'graphql'; 83 | const defaultDocument: DocumentNode; 84 | export const vote: DocumentNode; 85 | 86 | export default defaultDocument; 87 | } 88 | -------------------------------------------------------------------------------- /dev-test/githunt/new-entry.mutation.graphql: -------------------------------------------------------------------------------- 1 | mutation submitRepository($repoFullName: String!) { 2 | submitRepository(repoFullName: $repoFullName) { 3 | createdAt 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /dev-test/githunt/repo-info.fragment.graphql: -------------------------------------------------------------------------------- 1 | fragment RepoInfo on Entry { 2 | createdAt 3 | repository { 4 | description 5 | stargazers_count 6 | open_issues_count 7 | } 8 | postedBy { 9 | html_url 10 | login 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /dev-test/githunt/schema.js: -------------------------------------------------------------------------------- 1 | const introspectionSchema = require("./schema.json"); 2 | const GraphQL = require("graphql"); 3 | module.exports.default = GraphQL.buildClientSchema(introspectionSchema); 4 | -------------------------------------------------------------------------------- /dev-test/githunt/submit-comment.mutation.graphql: -------------------------------------------------------------------------------- 1 | mutation submitComment($repoFullName: String!, $commentContent: String!) { 2 | submitComment(repoFullName: $repoFullName, commentContent: $commentContent) { 3 | ...CommentsPageComment 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /dev-test/githunt/types.avoidOptionals.ts: -------------------------------------------------------------------------------- 1 | export type Maybe = T | null; 2 | export type Exact = { [K in keyof T]: T[K] }; 3 | /** All built-in and custom scalars, mapped to their actual values */ 4 | export type Scalars = { 5 | ID: string; 6 | String: string; 7 | Boolean: boolean; 8 | Int: number; 9 | Float: number; 10 | }; 11 | 12 | export type Query = { 13 | __typename?: 'Query'; 14 | /** A feed of repository submissions */ 15 | feed: Maybe>>; 16 | /** A single entry */ 17 | entry: Maybe; 18 | /** Return the currently logged in user, or null if nobody is logged in */ 19 | currentUser: Maybe; 20 | }; 21 | 22 | export type QueryFeedArgs = { 23 | type: FeedType; 24 | offset: Maybe; 25 | limit: Maybe; 26 | }; 27 | 28 | export type QueryEntryArgs = { 29 | repoFullName: Scalars['String']; 30 | }; 31 | 32 | /** A list of options for the sort order of the feed */ 33 | export enum FeedType { 34 | /** Sort by a combination of freshness and score, using Reddit's algorithm */ 35 | Hot = 'HOT', 36 | /** Newest entries first */ 37 | New = 'NEW', 38 | /** Highest score entries first */ 39 | Top = 'TOP', 40 | } 41 | 42 | /** Information about a GitHub repository submitted to GitHunt */ 43 | export type Entry = { 44 | __typename?: 'Entry'; 45 | /** Information about the repository from GitHub */ 46 | repository: Repository; 47 | /** The GitHub user who submitted this entry */ 48 | postedBy: User; 49 | /** A timestamp of when the entry was submitted */ 50 | createdAt: Scalars['Float']; 51 | /** The score of this repository, upvotes - downvotes */ 52 | score: Scalars['Int']; 53 | /** The hot score of this repository */ 54 | hotScore: Scalars['Float']; 55 | /** Comments posted about this repository */ 56 | comments: Array>; 57 | /** The number of comments posted about this repository */ 58 | commentCount: Scalars['Int']; 59 | /** The SQL ID of this entry */ 60 | id: Scalars['Int']; 61 | /** XXX to be changed */ 62 | vote: Vote; 63 | }; 64 | 65 | /** Information about a GitHub repository submitted to GitHunt */ 66 | export type EntryCommentsArgs = { 67 | limit: Maybe; 68 | offset: Maybe; 69 | }; 70 | 71 | /** 72 | * A repository object from the GitHub API. This uses the exact field names returned by the 73 | * GitHub API for simplicity, even though the convention for GraphQL is usually to camel case. 74 | */ 75 | export type Repository = { 76 | __typename?: 'Repository'; 77 | /** Just the name of the repository, e.g. GitHunt-API */ 78 | name: Scalars['String']; 79 | /** The full name of the repository with the username, e.g. apollostack/GitHunt-API */ 80 | full_name: Scalars['String']; 81 | /** The description of the repository */ 82 | description: Maybe; 83 | /** The link to the repository on GitHub */ 84 | html_url: Scalars['String']; 85 | /** The number of people who have starred this repository on GitHub */ 86 | stargazers_count: Scalars['Int']; 87 | /** The number of open issues on this repository on GitHub */ 88 | open_issues_count: Maybe; 89 | /** The owner of this repository on GitHub, e.g. apollostack */ 90 | owner: Maybe; 91 | }; 92 | 93 | /** A user object from the GitHub API. This uses the exact field names returned from the GitHub API. */ 94 | export type User = { 95 | __typename?: 'User'; 96 | /** The name of the user, e.g. apollostack */ 97 | login: Scalars['String']; 98 | /** The URL to a directly embeddable image for this user's avatar */ 99 | avatar_url: Scalars['String']; 100 | /** The URL of this user's GitHub page */ 101 | html_url: Scalars['String']; 102 | }; 103 | 104 | /** A comment about an entry, submitted by a user */ 105 | export type Comment = { 106 | __typename?: 'Comment'; 107 | /** The SQL ID of this entry */ 108 | id: Scalars['Int']; 109 | /** The GitHub user who posted the comment */ 110 | postedBy: User; 111 | /** A timestamp of when the comment was posted */ 112 | createdAt: Scalars['Float']; 113 | /** The text of the comment */ 114 | content: Scalars['String']; 115 | /** The repository which this comment is about */ 116 | repoName: Scalars['String']; 117 | }; 118 | 119 | /** XXX to be removed */ 120 | export type Vote = { 121 | __typename?: 'Vote'; 122 | vote_value: Scalars['Int']; 123 | }; 124 | 125 | export type Mutation = { 126 | __typename?: 'Mutation'; 127 | /** Submit a new repository, returns the new submission */ 128 | submitRepository: Maybe; 129 | /** Vote on a repository submission, returns the submission that was voted on */ 130 | vote: Maybe; 131 | /** Comment on a repository, returns the new comment */ 132 | submitComment: Maybe; 133 | }; 134 | 135 | export type MutationSubmitRepositoryArgs = { 136 | repoFullName: Scalars['String']; 137 | }; 138 | 139 | export type MutationVoteArgs = { 140 | repoFullName: Scalars['String']; 141 | type: VoteType; 142 | }; 143 | 144 | export type MutationSubmitCommentArgs = { 145 | repoFullName: Scalars['String']; 146 | commentContent: Scalars['String']; 147 | }; 148 | 149 | /** The type of vote to record, when submitting a vote */ 150 | export enum VoteType { 151 | Up = 'UP', 152 | Down = 'DOWN', 153 | Cancel = 'CANCEL', 154 | } 155 | 156 | export type Subscription = { 157 | __typename?: 'Subscription'; 158 | /** Subscription fires on every comment added */ 159 | commentAdded: Maybe; 160 | }; 161 | 162 | export type SubscriptionCommentAddedArgs = { 163 | repoFullName: Scalars['String']; 164 | }; 165 | 166 | export type OnCommentAddedSubscriptionVariables = Exact<{ 167 | repoFullName: Scalars['String']; 168 | }>; 169 | 170 | export type OnCommentAddedSubscription = { __typename?: 'Subscription' } & { 171 | commentAdded: Maybe< 172 | { __typename?: 'Comment' } & Pick & { 173 | postedBy: { __typename?: 'User' } & Pick; 174 | } 175 | >; 176 | }; 177 | 178 | export type CommentQueryVariables = Exact<{ 179 | repoFullName: Scalars['String']; 180 | limit: Maybe; 181 | offset: Maybe; 182 | }>; 183 | 184 | export type CommentQuery = { __typename?: 'Query' } & { 185 | currentUser: Maybe<{ __typename?: 'User' } & Pick>; 186 | entry: Maybe< 187 | { __typename?: 'Entry' } & Pick & { 188 | postedBy: { __typename?: 'User' } & Pick; 189 | comments: Array>; 190 | repository: { __typename?: 'Repository' } & Pick< 191 | Repository, 192 | 'description' | 'open_issues_count' | 'stargazers_count' | 'full_name' | 'html_url' 193 | >; 194 | } 195 | >; 196 | }; 197 | 198 | export type CommentsPageCommentFragment = { __typename?: 'Comment' } & Pick & { 199 | postedBy: { __typename?: 'User' } & Pick; 200 | }; 201 | 202 | export type CurrentUserForProfileQueryVariables = Exact<{ [key: string]: never }>; 203 | 204 | export type CurrentUserForProfileQuery = { __typename?: 'Query' } & { 205 | currentUser: Maybe<{ __typename?: 'User' } & Pick>; 206 | }; 207 | 208 | export type FeedEntryFragment = { __typename?: 'Entry' } & Pick & { 209 | repository: { __typename?: 'Repository' } & Pick & { 210 | owner: Maybe<{ __typename?: 'User' } & Pick>; 211 | }; 212 | } & VoteButtonsFragment & 213 | RepoInfoFragment; 214 | 215 | export type FeedQueryVariables = Exact<{ 216 | type: FeedType; 217 | offset: Maybe; 218 | limit: Maybe; 219 | }>; 220 | 221 | export type FeedQuery = { __typename?: 'Query' } & { 222 | currentUser: Maybe<{ __typename?: 'User' } & Pick>; 223 | feed: Maybe>>; 224 | }; 225 | 226 | export type SubmitRepositoryMutationVariables = Exact<{ 227 | repoFullName: Scalars['String']; 228 | }>; 229 | 230 | export type SubmitRepositoryMutation = { __typename?: 'Mutation' } & { 231 | submitRepository: Maybe<{ __typename?: 'Entry' } & Pick>; 232 | }; 233 | 234 | export type RepoInfoFragment = { __typename?: 'Entry' } & Pick & { 235 | repository: { __typename?: 'Repository' } & Pick< 236 | Repository, 237 | 'description' | 'stargazers_count' | 'open_issues_count' 238 | >; 239 | postedBy: { __typename?: 'User' } & Pick; 240 | }; 241 | 242 | export type SubmitCommentMutationVariables = Exact<{ 243 | repoFullName: Scalars['String']; 244 | commentContent: Scalars['String']; 245 | }>; 246 | 247 | export type SubmitCommentMutation = { __typename?: 'Mutation' } & { 248 | submitComment: Maybe<{ __typename?: 'Comment' } & CommentsPageCommentFragment>; 249 | }; 250 | 251 | export type VoteButtonsFragment = { __typename?: 'Entry' } & Pick & { 252 | vote: { __typename?: 'Vote' } & Pick; 253 | }; 254 | 255 | export type VoteMutationVariables = Exact<{ 256 | repoFullName: Scalars['String']; 257 | type: VoteType; 258 | }>; 259 | 260 | export type VoteMutation = { __typename?: 'Mutation' } & { 261 | vote: Maybe< 262 | { __typename?: 'Entry' } & Pick & { 263 | vote: { __typename?: 'Vote' } & Pick; 264 | } 265 | >; 266 | }; 267 | -------------------------------------------------------------------------------- /dev-test/githunt/types.d.ts: -------------------------------------------------------------------------------- 1 | export type Maybe = T | null; 2 | export type Exact = { [K in keyof T]: T[K] }; 3 | /** All built-in and custom scalars, mapped to their actual values */ 4 | export type Scalars = { 5 | ID: string; 6 | String: string; 7 | Boolean: boolean; 8 | Int: number; 9 | Float: number; 10 | }; 11 | 12 | export type Query = { 13 | __typename?: 'Query'; 14 | /** A feed of repository submissions */ 15 | feed?: Maybe>>; 16 | /** A single entry */ 17 | entry?: Maybe; 18 | /** Return the currently logged in user, or null if nobody is logged in */ 19 | currentUser?: Maybe; 20 | }; 21 | 22 | export type QueryFeedArgs = { 23 | type: FeedType; 24 | offset?: Maybe; 25 | limit?: Maybe; 26 | }; 27 | 28 | export type QueryEntryArgs = { 29 | repoFullName: Scalars['String']; 30 | }; 31 | 32 | /** A list of options for the sort order of the feed */ 33 | export type FeedType = 34 | /** Sort by a combination of freshness and score, using Reddit's algorithm */ 35 | | 'HOT' 36 | /** Newest entries first */ 37 | | 'NEW' 38 | /** Highest score entries first */ 39 | | 'TOP'; 40 | 41 | /** Information about a GitHub repository submitted to GitHunt */ 42 | export type Entry = { 43 | __typename?: 'Entry'; 44 | /** Information about the repository from GitHub */ 45 | repository: Repository; 46 | /** The GitHub user who submitted this entry */ 47 | postedBy: User; 48 | /** A timestamp of when the entry was submitted */ 49 | createdAt: Scalars['Float']; 50 | /** The score of this repository, upvotes - downvotes */ 51 | score: Scalars['Int']; 52 | /** The hot score of this repository */ 53 | hotScore: Scalars['Float']; 54 | /** Comments posted about this repository */ 55 | comments: Array>; 56 | /** The number of comments posted about this repository */ 57 | commentCount: Scalars['Int']; 58 | /** The SQL ID of this entry */ 59 | id: Scalars['Int']; 60 | /** XXX to be changed */ 61 | vote: Vote; 62 | }; 63 | 64 | /** Information about a GitHub repository submitted to GitHunt */ 65 | export type EntryCommentsArgs = { 66 | limit?: Maybe; 67 | offset?: Maybe; 68 | }; 69 | 70 | /** 71 | * A repository object from the GitHub API. This uses the exact field names returned by the 72 | * GitHub API for simplicity, even though the convention for GraphQL is usually to camel case. 73 | */ 74 | export type Repository = { 75 | __typename?: 'Repository'; 76 | /** Just the name of the repository, e.g. GitHunt-API */ 77 | name: Scalars['String']; 78 | /** The full name of the repository with the username, e.g. apollostack/GitHunt-API */ 79 | full_name: Scalars['String']; 80 | /** The description of the repository */ 81 | description?: Maybe; 82 | /** The link to the repository on GitHub */ 83 | html_url: Scalars['String']; 84 | /** The number of people who have starred this repository on GitHub */ 85 | stargazers_count: Scalars['Int']; 86 | /** The number of open issues on this repository on GitHub */ 87 | open_issues_count?: Maybe; 88 | /** The owner of this repository on GitHub, e.g. apollostack */ 89 | owner?: Maybe; 90 | }; 91 | 92 | /** A user object from the GitHub API. This uses the exact field names returned from the GitHub API. */ 93 | export type User = { 94 | __typename?: 'User'; 95 | /** The name of the user, e.g. apollostack */ 96 | login: Scalars['String']; 97 | /** The URL to a directly embeddable image for this user's avatar */ 98 | avatar_url: Scalars['String']; 99 | /** The URL of this user's GitHub page */ 100 | html_url: Scalars['String']; 101 | }; 102 | 103 | /** A comment about an entry, submitted by a user */ 104 | export type Comment = { 105 | __typename?: 'Comment'; 106 | /** The SQL ID of this entry */ 107 | id: Scalars['Int']; 108 | /** The GitHub user who posted the comment */ 109 | postedBy: User; 110 | /** A timestamp of when the comment was posted */ 111 | createdAt: Scalars['Float']; 112 | /** The text of the comment */ 113 | content: Scalars['String']; 114 | /** The repository which this comment is about */ 115 | repoName: Scalars['String']; 116 | }; 117 | 118 | /** XXX to be removed */ 119 | export type Vote = { 120 | __typename?: 'Vote'; 121 | vote_value: Scalars['Int']; 122 | }; 123 | 124 | export type Mutation = { 125 | __typename?: 'Mutation'; 126 | /** Submit a new repository, returns the new submission */ 127 | submitRepository?: Maybe; 128 | /** Vote on a repository submission, returns the submission that was voted on */ 129 | vote?: Maybe; 130 | /** Comment on a repository, returns the new comment */ 131 | submitComment?: Maybe; 132 | }; 133 | 134 | export type MutationSubmitRepositoryArgs = { 135 | repoFullName: Scalars['String']; 136 | }; 137 | 138 | export type MutationVoteArgs = { 139 | repoFullName: Scalars['String']; 140 | type: VoteType; 141 | }; 142 | 143 | export type MutationSubmitCommentArgs = { 144 | repoFullName: Scalars['String']; 145 | commentContent: Scalars['String']; 146 | }; 147 | 148 | /** The type of vote to record, when submitting a vote */ 149 | export type VoteType = 'UP' | 'DOWN' | 'CANCEL'; 150 | 151 | export type Subscription = { 152 | __typename?: 'Subscription'; 153 | /** Subscription fires on every comment added */ 154 | commentAdded?: Maybe; 155 | }; 156 | 157 | export type SubscriptionCommentAddedArgs = { 158 | repoFullName: Scalars['String']; 159 | }; 160 | 161 | export type OnCommentAddedSubscriptionVariables = Exact<{ 162 | repoFullName: Scalars['String']; 163 | }>; 164 | 165 | export type OnCommentAddedSubscription = { __typename?: 'Subscription' } & { 166 | commentAdded?: Maybe< 167 | { __typename?: 'Comment' } & Pick & { 168 | postedBy: { __typename?: 'User' } & Pick; 169 | } 170 | >; 171 | }; 172 | 173 | export type CommentQueryVariables = Exact<{ 174 | repoFullName: Scalars['String']; 175 | limit?: Maybe; 176 | offset?: Maybe; 177 | }>; 178 | 179 | export type CommentQuery = { __typename?: 'Query' } & { 180 | currentUser?: Maybe<{ __typename?: 'User' } & Pick>; 181 | entry?: Maybe< 182 | { __typename?: 'Entry' } & Pick & { 183 | postedBy: { __typename?: 'User' } & Pick; 184 | comments: Array>; 185 | repository: { __typename?: 'Repository' } & Pick< 186 | Repository, 187 | 'description' | 'open_issues_count' | 'stargazers_count' | 'full_name' | 'html_url' 188 | >; 189 | } 190 | >; 191 | }; 192 | 193 | export type CommentsPageCommentFragment = { __typename?: 'Comment' } & Pick & { 194 | postedBy: { __typename?: 'User' } & Pick; 195 | }; 196 | 197 | export type CurrentUserForProfileQueryVariables = Exact<{ [key: string]: never }>; 198 | 199 | export type CurrentUserForProfileQuery = { __typename?: 'Query' } & { 200 | currentUser?: Maybe<{ __typename?: 'User' } & Pick>; 201 | }; 202 | 203 | export type FeedEntryFragment = { __typename?: 'Entry' } & Pick & { 204 | repository: { __typename?: 'Repository' } & Pick & { 205 | owner?: Maybe<{ __typename?: 'User' } & Pick>; 206 | }; 207 | } & VoteButtonsFragment & 208 | RepoInfoFragment; 209 | 210 | export type FeedQueryVariables = Exact<{ 211 | type: FeedType; 212 | offset?: Maybe; 213 | limit?: Maybe; 214 | }>; 215 | 216 | export type FeedQuery = { __typename?: 'Query' } & { 217 | currentUser?: Maybe<{ __typename?: 'User' } & Pick>; 218 | feed?: Maybe>>; 219 | }; 220 | 221 | export type SubmitRepositoryMutationVariables = Exact<{ 222 | repoFullName: Scalars['String']; 223 | }>; 224 | 225 | export type SubmitRepositoryMutation = { __typename?: 'Mutation' } & { 226 | submitRepository?: Maybe<{ __typename?: 'Entry' } & Pick>; 227 | }; 228 | 229 | export type RepoInfoFragment = { __typename?: 'Entry' } & Pick & { 230 | repository: { __typename?: 'Repository' } & Pick< 231 | Repository, 232 | 'description' | 'stargazers_count' | 'open_issues_count' 233 | >; 234 | postedBy: { __typename?: 'User' } & Pick; 235 | }; 236 | 237 | export type SubmitCommentMutationVariables = Exact<{ 238 | repoFullName: Scalars['String']; 239 | commentContent: Scalars['String']; 240 | }>; 241 | 242 | export type SubmitCommentMutation = { __typename?: 'Mutation' } & { 243 | submitComment?: Maybe<{ __typename?: 'Comment' } & CommentsPageCommentFragment>; 244 | }; 245 | 246 | export type VoteButtonsFragment = { __typename?: 'Entry' } & Pick & { 247 | vote: { __typename?: 'Vote' } & Pick; 248 | }; 249 | 250 | export type VoteMutationVariables = Exact<{ 251 | repoFullName: Scalars['String']; 252 | type: VoteType; 253 | }>; 254 | 255 | export type VoteMutation = { __typename?: 'Mutation' } & { 256 | vote?: Maybe< 257 | { __typename?: 'Entry' } & Pick & { 258 | vote: { __typename?: 'Vote' } & Pick; 259 | } 260 | >; 261 | }; 262 | -------------------------------------------------------------------------------- /dev-test/githunt/types.enumsAsTypes.ts: -------------------------------------------------------------------------------- 1 | export type Maybe = T | null; 2 | export type Exact = { [K in keyof T]: T[K] }; 3 | /** All built-in and custom scalars, mapped to their actual values */ 4 | export type Scalars = { 5 | ID: string; 6 | String: string; 7 | Boolean: boolean; 8 | Int: number; 9 | Float: number; 10 | }; 11 | 12 | export type Query = { 13 | __typename?: 'Query'; 14 | /** A feed of repository submissions */ 15 | feed?: Maybe>>; 16 | /** A single entry */ 17 | entry?: Maybe; 18 | /** Return the currently logged in user, or null if nobody is logged in */ 19 | currentUser?: Maybe; 20 | }; 21 | 22 | export type QueryFeedArgs = { 23 | type: FeedType; 24 | offset?: Maybe; 25 | limit?: Maybe; 26 | }; 27 | 28 | export type QueryEntryArgs = { 29 | repoFullName: Scalars['String']; 30 | }; 31 | 32 | /** A list of options for the sort order of the feed */ 33 | export type FeedType = 34 | /** Sort by a combination of freshness and score, using Reddit's algorithm */ 35 | | 'HOT' 36 | /** Newest entries first */ 37 | | 'NEW' 38 | /** Highest score entries first */ 39 | | 'TOP'; 40 | 41 | /** Information about a GitHub repository submitted to GitHunt */ 42 | export type Entry = { 43 | __typename?: 'Entry'; 44 | /** Information about the repository from GitHub */ 45 | repository: Repository; 46 | /** The GitHub user who submitted this entry */ 47 | postedBy: User; 48 | /** A timestamp of when the entry was submitted */ 49 | createdAt: Scalars['Float']; 50 | /** The score of this repository, upvotes - downvotes */ 51 | score: Scalars['Int']; 52 | /** The hot score of this repository */ 53 | hotScore: Scalars['Float']; 54 | /** Comments posted about this repository */ 55 | comments: Array>; 56 | /** The number of comments posted about this repository */ 57 | commentCount: Scalars['Int']; 58 | /** The SQL ID of this entry */ 59 | id: Scalars['Int']; 60 | /** XXX to be changed */ 61 | vote: Vote; 62 | }; 63 | 64 | /** Information about a GitHub repository submitted to GitHunt */ 65 | export type EntryCommentsArgs = { 66 | limit?: Maybe; 67 | offset?: Maybe; 68 | }; 69 | 70 | /** 71 | * A repository object from the GitHub API. This uses the exact field names returned by the 72 | * GitHub API for simplicity, even though the convention for GraphQL is usually to camel case. 73 | */ 74 | export type Repository = { 75 | __typename?: 'Repository'; 76 | /** Just the name of the repository, e.g. GitHunt-API */ 77 | name: Scalars['String']; 78 | /** The full name of the repository with the username, e.g. apollostack/GitHunt-API */ 79 | full_name: Scalars['String']; 80 | /** The description of the repository */ 81 | description?: Maybe; 82 | /** The link to the repository on GitHub */ 83 | html_url: Scalars['String']; 84 | /** The number of people who have starred this repository on GitHub */ 85 | stargazers_count: Scalars['Int']; 86 | /** The number of open issues on this repository on GitHub */ 87 | open_issues_count?: Maybe; 88 | /** The owner of this repository on GitHub, e.g. apollostack */ 89 | owner?: Maybe; 90 | }; 91 | 92 | /** A user object from the GitHub API. This uses the exact field names returned from the GitHub API. */ 93 | export type User = { 94 | __typename?: 'User'; 95 | /** The name of the user, e.g. apollostack */ 96 | login: Scalars['String']; 97 | /** The URL to a directly embeddable image for this user's avatar */ 98 | avatar_url: Scalars['String']; 99 | /** The URL of this user's GitHub page */ 100 | html_url: Scalars['String']; 101 | }; 102 | 103 | /** A comment about an entry, submitted by a user */ 104 | export type Comment = { 105 | __typename?: 'Comment'; 106 | /** The SQL ID of this entry */ 107 | id: Scalars['Int']; 108 | /** The GitHub user who posted the comment */ 109 | postedBy: User; 110 | /** A timestamp of when the comment was posted */ 111 | createdAt: Scalars['Float']; 112 | /** The text of the comment */ 113 | content: Scalars['String']; 114 | /** The repository which this comment is about */ 115 | repoName: Scalars['String']; 116 | }; 117 | 118 | /** XXX to be removed */ 119 | export type Vote = { 120 | __typename?: 'Vote'; 121 | vote_value: Scalars['Int']; 122 | }; 123 | 124 | export type Mutation = { 125 | __typename?: 'Mutation'; 126 | /** Submit a new repository, returns the new submission */ 127 | submitRepository?: Maybe; 128 | /** Vote on a repository submission, returns the submission that was voted on */ 129 | vote?: Maybe; 130 | /** Comment on a repository, returns the new comment */ 131 | submitComment?: Maybe; 132 | }; 133 | 134 | export type MutationSubmitRepositoryArgs = { 135 | repoFullName: Scalars['String']; 136 | }; 137 | 138 | export type MutationVoteArgs = { 139 | repoFullName: Scalars['String']; 140 | type: VoteType; 141 | }; 142 | 143 | export type MutationSubmitCommentArgs = { 144 | repoFullName: Scalars['String']; 145 | commentContent: Scalars['String']; 146 | }; 147 | 148 | /** The type of vote to record, when submitting a vote */ 149 | export type VoteType = 'UP' | 'DOWN' | 'CANCEL'; 150 | 151 | export type Subscription = { 152 | __typename?: 'Subscription'; 153 | /** Subscription fires on every comment added */ 154 | commentAdded?: Maybe; 155 | }; 156 | 157 | export type SubscriptionCommentAddedArgs = { 158 | repoFullName: Scalars['String']; 159 | }; 160 | 161 | export type OnCommentAddedSubscriptionVariables = Exact<{ 162 | repoFullName: Scalars['String']; 163 | }>; 164 | 165 | export type OnCommentAddedSubscription = { __typename?: 'Subscription' } & { 166 | commentAdded?: Maybe< 167 | { __typename?: 'Comment' } & Pick & { 168 | postedBy: { __typename?: 'User' } & Pick; 169 | } 170 | >; 171 | }; 172 | 173 | export type CommentQueryVariables = Exact<{ 174 | repoFullName: Scalars['String']; 175 | limit?: Maybe; 176 | offset?: Maybe; 177 | }>; 178 | 179 | export type CommentQuery = { __typename?: 'Query' } & { 180 | currentUser?: Maybe<{ __typename?: 'User' } & Pick>; 181 | entry?: Maybe< 182 | { __typename?: 'Entry' } & Pick & { 183 | postedBy: { __typename?: 'User' } & Pick; 184 | comments: Array>; 185 | repository: { __typename?: 'Repository' } & Pick< 186 | Repository, 187 | 'description' | 'open_issues_count' | 'stargazers_count' | 'full_name' | 'html_url' 188 | >; 189 | } 190 | >; 191 | }; 192 | 193 | export type CommentsPageCommentFragment = { __typename?: 'Comment' } & Pick & { 194 | postedBy: { __typename?: 'User' } & Pick; 195 | }; 196 | 197 | export type CurrentUserForProfileQueryVariables = Exact<{ [key: string]: never }>; 198 | 199 | export type CurrentUserForProfileQuery = { __typename?: 'Query' } & { 200 | currentUser?: Maybe<{ __typename?: 'User' } & Pick>; 201 | }; 202 | 203 | export type FeedEntryFragment = { __typename?: 'Entry' } & Pick & { 204 | repository: { __typename?: 'Repository' } & Pick & { 205 | owner?: Maybe<{ __typename?: 'User' } & Pick>; 206 | }; 207 | } & VoteButtonsFragment & 208 | RepoInfoFragment; 209 | 210 | export type FeedQueryVariables = Exact<{ 211 | type: FeedType; 212 | offset?: Maybe; 213 | limit?: Maybe; 214 | }>; 215 | 216 | export type FeedQuery = { __typename?: 'Query' } & { 217 | currentUser?: Maybe<{ __typename?: 'User' } & Pick>; 218 | feed?: Maybe>>; 219 | }; 220 | 221 | export type SubmitRepositoryMutationVariables = Exact<{ 222 | repoFullName: Scalars['String']; 223 | }>; 224 | 225 | export type SubmitRepositoryMutation = { __typename?: 'Mutation' } & { 226 | submitRepository?: Maybe<{ __typename?: 'Entry' } & Pick>; 227 | }; 228 | 229 | export type RepoInfoFragment = { __typename?: 'Entry' } & Pick & { 230 | repository: { __typename?: 'Repository' } & Pick< 231 | Repository, 232 | 'description' | 'stargazers_count' | 'open_issues_count' 233 | >; 234 | postedBy: { __typename?: 'User' } & Pick; 235 | }; 236 | 237 | export type SubmitCommentMutationVariables = Exact<{ 238 | repoFullName: Scalars['String']; 239 | commentContent: Scalars['String']; 240 | }>; 241 | 242 | export type SubmitCommentMutation = { __typename?: 'Mutation' } & { 243 | submitComment?: Maybe<{ __typename?: 'Comment' } & CommentsPageCommentFragment>; 244 | }; 245 | 246 | export type VoteButtonsFragment = { __typename?: 'Entry' } & Pick & { 247 | vote: { __typename?: 'Vote' } & Pick; 248 | }; 249 | 250 | export type VoteMutationVariables = Exact<{ 251 | repoFullName: Scalars['String']; 252 | type: VoteType; 253 | }>; 254 | 255 | export type VoteMutation = { __typename?: 'Mutation' } & { 256 | vote?: Maybe< 257 | { __typename?: 'Entry' } & Pick & { 258 | vote: { __typename?: 'Vote' } & Pick; 259 | } 260 | >; 261 | }; 262 | -------------------------------------------------------------------------------- /dev-test/githunt/types.flatten.preResolveTypes.ts: -------------------------------------------------------------------------------- 1 | export type Maybe = T | null; 2 | export type Exact = { [K in keyof T]: T[K] }; 3 | /** All built-in and custom scalars, mapped to their actual values */ 4 | export type Scalars = { 5 | ID: string; 6 | String: string; 7 | Boolean: boolean; 8 | Int: number; 9 | Float: number; 10 | }; 11 | 12 | export type Query = { 13 | __typename?: 'Query'; 14 | /** A feed of repository submissions */ 15 | feed?: Maybe>>; 16 | /** A single entry */ 17 | entry?: Maybe; 18 | /** Return the currently logged in user, or null if nobody is logged in */ 19 | currentUser?: Maybe; 20 | }; 21 | 22 | export type QueryFeedArgs = { 23 | type: FeedType; 24 | offset?: Maybe; 25 | limit?: Maybe; 26 | }; 27 | 28 | export type QueryEntryArgs = { 29 | repoFullName: Scalars['String']; 30 | }; 31 | 32 | /** A list of options for the sort order of the feed */ 33 | export enum FeedType { 34 | /** Sort by a combination of freshness and score, using Reddit's algorithm */ 35 | Hot = 'HOT', 36 | /** Newest entries first */ 37 | New = 'NEW', 38 | /** Highest score entries first */ 39 | Top = 'TOP', 40 | } 41 | 42 | /** Information about a GitHub repository submitted to GitHunt */ 43 | export type Entry = { 44 | __typename?: 'Entry'; 45 | /** Information about the repository from GitHub */ 46 | repository: Repository; 47 | /** The GitHub user who submitted this entry */ 48 | postedBy: User; 49 | /** A timestamp of when the entry was submitted */ 50 | createdAt: Scalars['Float']; 51 | /** The score of this repository, upvotes - downvotes */ 52 | score: Scalars['Int']; 53 | /** The hot score of this repository */ 54 | hotScore: Scalars['Float']; 55 | /** Comments posted about this repository */ 56 | comments: Array>; 57 | /** The number of comments posted about this repository */ 58 | commentCount: Scalars['Int']; 59 | /** The SQL ID of this entry */ 60 | id: Scalars['Int']; 61 | /** XXX to be changed */ 62 | vote: Vote; 63 | }; 64 | 65 | /** Information about a GitHub repository submitted to GitHunt */ 66 | export type EntryCommentsArgs = { 67 | limit?: Maybe; 68 | offset?: Maybe; 69 | }; 70 | 71 | /** 72 | * A repository object from the GitHub API. This uses the exact field names returned by the 73 | * GitHub API for simplicity, even though the convention for GraphQL is usually to camel case. 74 | */ 75 | export type Repository = { 76 | __typename?: 'Repository'; 77 | /** Just the name of the repository, e.g. GitHunt-API */ 78 | name: Scalars['String']; 79 | /** The full name of the repository with the username, e.g. apollostack/GitHunt-API */ 80 | full_name: Scalars['String']; 81 | /** The description of the repository */ 82 | description?: Maybe; 83 | /** The link to the repository on GitHub */ 84 | html_url: Scalars['String']; 85 | /** The number of people who have starred this repository on GitHub */ 86 | stargazers_count: Scalars['Int']; 87 | /** The number of open issues on this repository on GitHub */ 88 | open_issues_count?: Maybe; 89 | /** The owner of this repository on GitHub, e.g. apollostack */ 90 | owner?: Maybe; 91 | }; 92 | 93 | /** A user object from the GitHub API. This uses the exact field names returned from the GitHub API. */ 94 | export type User = { 95 | __typename?: 'User'; 96 | /** The name of the user, e.g. apollostack */ 97 | login: Scalars['String']; 98 | /** The URL to a directly embeddable image for this user's avatar */ 99 | avatar_url: Scalars['String']; 100 | /** The URL of this user's GitHub page */ 101 | html_url: Scalars['String']; 102 | }; 103 | 104 | /** A comment about an entry, submitted by a user */ 105 | export type Comment = { 106 | __typename?: 'Comment'; 107 | /** The SQL ID of this entry */ 108 | id: Scalars['Int']; 109 | /** The GitHub user who posted the comment */ 110 | postedBy: User; 111 | /** A timestamp of when the comment was posted */ 112 | createdAt: Scalars['Float']; 113 | /** The text of the comment */ 114 | content: Scalars['String']; 115 | /** The repository which this comment is about */ 116 | repoName: Scalars['String']; 117 | }; 118 | 119 | /** XXX to be removed */ 120 | export type Vote = { 121 | __typename?: 'Vote'; 122 | vote_value: Scalars['Int']; 123 | }; 124 | 125 | export type Mutation = { 126 | __typename?: 'Mutation'; 127 | /** Submit a new repository, returns the new submission */ 128 | submitRepository?: Maybe; 129 | /** Vote on a repository submission, returns the submission that was voted on */ 130 | vote?: Maybe; 131 | /** Comment on a repository, returns the new comment */ 132 | submitComment?: Maybe; 133 | }; 134 | 135 | export type MutationSubmitRepositoryArgs = { 136 | repoFullName: Scalars['String']; 137 | }; 138 | 139 | export type MutationVoteArgs = { 140 | repoFullName: Scalars['String']; 141 | type: VoteType; 142 | }; 143 | 144 | export type MutationSubmitCommentArgs = { 145 | repoFullName: Scalars['String']; 146 | commentContent: Scalars['String']; 147 | }; 148 | 149 | /** The type of vote to record, when submitting a vote */ 150 | export enum VoteType { 151 | Up = 'UP', 152 | Down = 'DOWN', 153 | Cancel = 'CANCEL', 154 | } 155 | 156 | export type Subscription = { 157 | __typename?: 'Subscription'; 158 | /** Subscription fires on every comment added */ 159 | commentAdded?: Maybe; 160 | }; 161 | 162 | export type SubscriptionCommentAddedArgs = { 163 | repoFullName: Scalars['String']; 164 | }; 165 | 166 | export type OnCommentAddedSubscriptionVariables = Exact<{ 167 | repoFullName: Scalars['String']; 168 | }>; 169 | 170 | export type OnCommentAddedSubscription = { 171 | __typename?: 'Subscription'; 172 | commentAdded?: Maybe<{ 173 | __typename?: 'Comment'; 174 | id: number; 175 | createdAt: number; 176 | content: string; 177 | postedBy: { __typename?: 'User'; login: string; html_url: string }; 178 | }>; 179 | }; 180 | 181 | export type CommentQueryVariables = Exact<{ 182 | repoFullName: Scalars['String']; 183 | limit?: Maybe; 184 | offset?: Maybe; 185 | }>; 186 | 187 | export type CommentQuery = { 188 | __typename?: 'Query'; 189 | currentUser?: Maybe<{ __typename?: 'User'; login: string; html_url: string }>; 190 | entry?: Maybe<{ 191 | __typename?: 'Entry'; 192 | id: number; 193 | createdAt: number; 194 | commentCount: number; 195 | postedBy: { __typename?: 'User'; login: string; html_url: string }; 196 | comments: Array< 197 | Maybe<{ 198 | __typename?: 'Comment'; 199 | id: number; 200 | createdAt: number; 201 | content: string; 202 | postedBy: { __typename?: 'User'; login: string; html_url: string }; 203 | }> 204 | >; 205 | repository: { 206 | __typename?: 'Repository'; 207 | full_name: string; 208 | html_url: string; 209 | description?: Maybe; 210 | open_issues_count?: Maybe; 211 | stargazers_count: number; 212 | }; 213 | }>; 214 | }; 215 | 216 | export type CurrentUserForProfileQueryVariables = Exact<{ [key: string]: never }>; 217 | 218 | export type CurrentUserForProfileQuery = { 219 | __typename?: 'Query'; 220 | currentUser?: Maybe<{ __typename?: 'User'; login: string; avatar_url: string }>; 221 | }; 222 | 223 | export type FeedQueryVariables = Exact<{ 224 | type: FeedType; 225 | offset?: Maybe; 226 | limit?: Maybe; 227 | }>; 228 | 229 | export type FeedQuery = { 230 | __typename?: 'Query'; 231 | currentUser?: Maybe<{ __typename?: 'User'; login: string }>; 232 | feed?: Maybe< 233 | Array< 234 | Maybe<{ 235 | __typename?: 'Entry'; 236 | id: number; 237 | commentCount: number; 238 | score: number; 239 | createdAt: number; 240 | repository: { 241 | __typename?: 'Repository'; 242 | full_name: string; 243 | html_url: string; 244 | description?: Maybe; 245 | stargazers_count: number; 246 | open_issues_count?: Maybe; 247 | owner?: Maybe<{ __typename?: 'User'; avatar_url: string }>; 248 | }; 249 | vote: { __typename?: 'Vote'; vote_value: number }; 250 | postedBy: { __typename?: 'User'; html_url: string; login: string }; 251 | }> 252 | > 253 | >; 254 | }; 255 | 256 | export type SubmitRepositoryMutationVariables = Exact<{ 257 | repoFullName: Scalars['String']; 258 | }>; 259 | 260 | export type SubmitRepositoryMutation = { 261 | __typename?: 'Mutation'; 262 | submitRepository?: Maybe<{ __typename?: 'Entry'; createdAt: number }>; 263 | }; 264 | 265 | export type SubmitCommentMutationVariables = Exact<{ 266 | repoFullName: Scalars['String']; 267 | commentContent: Scalars['String']; 268 | }>; 269 | 270 | export type SubmitCommentMutation = { 271 | __typename?: 'Mutation'; 272 | submitComment?: Maybe<{ 273 | __typename?: 'Comment'; 274 | id: number; 275 | createdAt: number; 276 | content: string; 277 | postedBy: { __typename?: 'User'; login: string; html_url: string }; 278 | }>; 279 | }; 280 | 281 | export type VoteMutationVariables = Exact<{ 282 | repoFullName: Scalars['String']; 283 | type: VoteType; 284 | }>; 285 | 286 | export type VoteMutation = { 287 | __typename?: 'Mutation'; 288 | vote?: Maybe<{ __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } }>; 289 | }; 290 | -------------------------------------------------------------------------------- /dev-test/githunt/types.immutableTypes.ts: -------------------------------------------------------------------------------- 1 | export type Maybe = T | null; 2 | export type Exact = { [K in keyof T]: T[K] }; 3 | /** All built-in and custom scalars, mapped to their actual values */ 4 | export type Scalars = { 5 | ID: string; 6 | String: string; 7 | Boolean: boolean; 8 | Int: number; 9 | Float: number; 10 | }; 11 | 12 | export type Query = { 13 | readonly __typename?: 'Query'; 14 | /** A feed of repository submissions */ 15 | readonly feed?: Maybe>>; 16 | /** A single entry */ 17 | readonly entry?: Maybe; 18 | /** Return the currently logged in user, or null if nobody is logged in */ 19 | readonly currentUser?: Maybe; 20 | }; 21 | 22 | export type QueryFeedArgs = { 23 | type: FeedType; 24 | offset?: Maybe; 25 | limit?: Maybe; 26 | }; 27 | 28 | export type QueryEntryArgs = { 29 | repoFullName: Scalars['String']; 30 | }; 31 | 32 | /** A list of options for the sort order of the feed */ 33 | export enum FeedType { 34 | /** Sort by a combination of freshness and score, using Reddit's algorithm */ 35 | Hot = 'HOT', 36 | /** Newest entries first */ 37 | New = 'NEW', 38 | /** Highest score entries first */ 39 | Top = 'TOP', 40 | } 41 | 42 | /** Information about a GitHub repository submitted to GitHunt */ 43 | export type Entry = { 44 | readonly __typename?: 'Entry'; 45 | /** Information about the repository from GitHub */ 46 | readonly repository: Repository; 47 | /** The GitHub user who submitted this entry */ 48 | readonly postedBy: User; 49 | /** A timestamp of when the entry was submitted */ 50 | readonly createdAt: Scalars['Float']; 51 | /** The score of this repository, upvotes - downvotes */ 52 | readonly score: Scalars['Int']; 53 | /** The hot score of this repository */ 54 | readonly hotScore: Scalars['Float']; 55 | /** Comments posted about this repository */ 56 | readonly comments: ReadonlyArray>; 57 | /** The number of comments posted about this repository */ 58 | readonly commentCount: Scalars['Int']; 59 | /** The SQL ID of this entry */ 60 | readonly id: Scalars['Int']; 61 | /** XXX to be changed */ 62 | readonly vote: Vote; 63 | }; 64 | 65 | /** Information about a GitHub repository submitted to GitHunt */ 66 | export type EntryCommentsArgs = { 67 | limit?: Maybe; 68 | offset?: Maybe; 69 | }; 70 | 71 | /** 72 | * A repository object from the GitHub API. This uses the exact field names returned by the 73 | * GitHub API for simplicity, even though the convention for GraphQL is usually to camel case. 74 | */ 75 | export type Repository = { 76 | readonly __typename?: 'Repository'; 77 | /** Just the name of the repository, e.g. GitHunt-API */ 78 | readonly name: Scalars['String']; 79 | /** The full name of the repository with the username, e.g. apollostack/GitHunt-API */ 80 | readonly full_name: Scalars['String']; 81 | /** The description of the repository */ 82 | readonly description?: Maybe; 83 | /** The link to the repository on GitHub */ 84 | readonly html_url: Scalars['String']; 85 | /** The number of people who have starred this repository on GitHub */ 86 | readonly stargazers_count: Scalars['Int']; 87 | /** The number of open issues on this repository on GitHub */ 88 | readonly open_issues_count?: Maybe; 89 | /** The owner of this repository on GitHub, e.g. apollostack */ 90 | readonly owner?: Maybe; 91 | }; 92 | 93 | /** A user object from the GitHub API. This uses the exact field names returned from the GitHub API. */ 94 | export type User = { 95 | readonly __typename?: 'User'; 96 | /** The name of the user, e.g. apollostack */ 97 | readonly login: Scalars['String']; 98 | /** The URL to a directly embeddable image for this user's avatar */ 99 | readonly avatar_url: Scalars['String']; 100 | /** The URL of this user's GitHub page */ 101 | readonly html_url: Scalars['String']; 102 | }; 103 | 104 | /** A comment about an entry, submitted by a user */ 105 | export type Comment = { 106 | readonly __typename?: 'Comment'; 107 | /** The SQL ID of this entry */ 108 | readonly id: Scalars['Int']; 109 | /** The GitHub user who posted the comment */ 110 | readonly postedBy: User; 111 | /** A timestamp of when the comment was posted */ 112 | readonly createdAt: Scalars['Float']; 113 | /** The text of the comment */ 114 | readonly content: Scalars['String']; 115 | /** The repository which this comment is about */ 116 | readonly repoName: Scalars['String']; 117 | }; 118 | 119 | /** XXX to be removed */ 120 | export type Vote = { 121 | readonly __typename?: 'Vote'; 122 | readonly vote_value: Scalars['Int']; 123 | }; 124 | 125 | export type Mutation = { 126 | readonly __typename?: 'Mutation'; 127 | /** Submit a new repository, returns the new submission */ 128 | readonly submitRepository?: Maybe; 129 | /** Vote on a repository submission, returns the submission that was voted on */ 130 | readonly vote?: Maybe; 131 | /** Comment on a repository, returns the new comment */ 132 | readonly submitComment?: Maybe; 133 | }; 134 | 135 | export type MutationSubmitRepositoryArgs = { 136 | repoFullName: Scalars['String']; 137 | }; 138 | 139 | export type MutationVoteArgs = { 140 | repoFullName: Scalars['String']; 141 | type: VoteType; 142 | }; 143 | 144 | export type MutationSubmitCommentArgs = { 145 | repoFullName: Scalars['String']; 146 | commentContent: Scalars['String']; 147 | }; 148 | 149 | /** The type of vote to record, when submitting a vote */ 150 | export enum VoteType { 151 | Up = 'UP', 152 | Down = 'DOWN', 153 | Cancel = 'CANCEL', 154 | } 155 | 156 | export type Subscription = { 157 | readonly __typename?: 'Subscription'; 158 | /** Subscription fires on every comment added */ 159 | readonly commentAdded?: Maybe; 160 | }; 161 | 162 | export type SubscriptionCommentAddedArgs = { 163 | repoFullName: Scalars['String']; 164 | }; 165 | 166 | export type OnCommentAddedSubscriptionVariables = Exact<{ 167 | repoFullName: Scalars['String']; 168 | }>; 169 | 170 | export type OnCommentAddedSubscription = { readonly __typename?: 'Subscription' } & { 171 | readonly commentAdded?: Maybe< 172 | { readonly __typename?: 'Comment' } & Pick & { 173 | readonly postedBy: { readonly __typename?: 'User' } & Pick; 174 | } 175 | >; 176 | }; 177 | 178 | export type CommentQueryVariables = Exact<{ 179 | repoFullName: Scalars['String']; 180 | limit?: Maybe; 181 | offset?: Maybe; 182 | }>; 183 | 184 | export type CommentQuery = { readonly __typename?: 'Query' } & { 185 | readonly currentUser?: Maybe<{ readonly __typename?: 'User' } & Pick>; 186 | readonly entry?: Maybe< 187 | { readonly __typename?: 'Entry' } & Pick & { 188 | readonly postedBy: { readonly __typename?: 'User' } & Pick; 189 | readonly comments: ReadonlyArray>; 190 | readonly repository: { readonly __typename?: 'Repository' } & Pick< 191 | Repository, 192 | 'description' | 'open_issues_count' | 'stargazers_count' | 'full_name' | 'html_url' 193 | >; 194 | } 195 | >; 196 | }; 197 | 198 | export type CommentsPageCommentFragment = { readonly __typename?: 'Comment' } & Pick< 199 | Comment, 200 | 'id' | 'createdAt' | 'content' 201 | > & { readonly postedBy: { readonly __typename?: 'User' } & Pick }; 202 | 203 | export type CurrentUserForProfileQueryVariables = Exact<{ [key: string]: never }>; 204 | 205 | export type CurrentUserForProfileQuery = { readonly __typename?: 'Query' } & { 206 | readonly currentUser?: Maybe<{ readonly __typename?: 'User' } & Pick>; 207 | }; 208 | 209 | export type FeedEntryFragment = { readonly __typename?: 'Entry' } & Pick & { 210 | readonly repository: { readonly __typename?: 'Repository' } & Pick & { 211 | readonly owner?: Maybe<{ readonly __typename?: 'User' } & Pick>; 212 | }; 213 | } & VoteButtonsFragment & 214 | RepoInfoFragment; 215 | 216 | export type FeedQueryVariables = Exact<{ 217 | type: FeedType; 218 | offset?: Maybe; 219 | limit?: Maybe; 220 | }>; 221 | 222 | export type FeedQuery = { readonly __typename?: 'Query' } & { 223 | readonly currentUser?: Maybe<{ readonly __typename?: 'User' } & Pick>; 224 | readonly feed?: Maybe>>; 225 | }; 226 | 227 | export type SubmitRepositoryMutationVariables = Exact<{ 228 | repoFullName: Scalars['String']; 229 | }>; 230 | 231 | export type SubmitRepositoryMutation = { readonly __typename?: 'Mutation' } & { 232 | readonly submitRepository?: Maybe<{ readonly __typename?: 'Entry' } & Pick>; 233 | }; 234 | 235 | export type RepoInfoFragment = { readonly __typename?: 'Entry' } & Pick & { 236 | readonly repository: { readonly __typename?: 'Repository' } & Pick< 237 | Repository, 238 | 'description' | 'stargazers_count' | 'open_issues_count' 239 | >; 240 | readonly postedBy: { readonly __typename?: 'User' } & Pick; 241 | }; 242 | 243 | export type SubmitCommentMutationVariables = Exact<{ 244 | repoFullName: Scalars['String']; 245 | commentContent: Scalars['String']; 246 | }>; 247 | 248 | export type SubmitCommentMutation = { readonly __typename?: 'Mutation' } & { 249 | readonly submitComment?: Maybe<{ readonly __typename?: 'Comment' } & CommentsPageCommentFragment>; 250 | }; 251 | 252 | export type VoteButtonsFragment = { readonly __typename?: 'Entry' } & Pick & { 253 | readonly vote: { readonly __typename?: 'Vote' } & Pick; 254 | }; 255 | 256 | export type VoteMutationVariables = Exact<{ 257 | repoFullName: Scalars['String']; 258 | type: VoteType; 259 | }>; 260 | 261 | export type VoteMutation = { readonly __typename?: 'Mutation' } & { 262 | readonly vote?: Maybe< 263 | { readonly __typename?: 'Entry' } & Pick & { 264 | readonly vote: { readonly __typename?: 'Vote' } & Pick; 265 | } 266 | >; 267 | }; 268 | -------------------------------------------------------------------------------- /dev-test/githunt/types.preResolveTypes.onlyOperationTypes.ts: -------------------------------------------------------------------------------- 1 | export type Maybe = T | null; 2 | export type Exact = { [K in keyof T]: T[K] }; 3 | /** All built-in and custom scalars, mapped to their actual values */ 4 | export type Scalars = { 5 | ID: string; 6 | String: string; 7 | Boolean: boolean; 8 | Int: number; 9 | Float: number; 10 | }; 11 | 12 | /** A list of options for the sort order of the feed */ 13 | export enum FeedType { 14 | /** Sort by a combination of freshness and score, using Reddit's algorithm */ 15 | Hot = 'HOT', 16 | /** Newest entries first */ 17 | New = 'NEW', 18 | /** Highest score entries first */ 19 | Top = 'TOP', 20 | } 21 | 22 | /** The type of vote to record, when submitting a vote */ 23 | export enum VoteType { 24 | Up = 'UP', 25 | Down = 'DOWN', 26 | Cancel = 'CANCEL', 27 | } 28 | 29 | export type OnCommentAddedSubscriptionVariables = Exact<{ 30 | repoFullName: Scalars['String']; 31 | }>; 32 | 33 | export type OnCommentAddedSubscription = { 34 | __typename?: 'Subscription'; 35 | commentAdded?: Maybe<{ 36 | __typename?: 'Comment'; 37 | id: number; 38 | createdAt: number; 39 | content: string; 40 | postedBy: { __typename?: 'User'; login: string; html_url: string }; 41 | }>; 42 | }; 43 | 44 | export type CommentQueryVariables = Exact<{ 45 | repoFullName: Scalars['String']; 46 | limit?: Maybe; 47 | offset?: Maybe; 48 | }>; 49 | 50 | export type CommentQuery = { 51 | __typename?: 'Query'; 52 | currentUser?: Maybe<{ __typename?: 'User'; login: string; html_url: string }>; 53 | entry?: Maybe<{ 54 | __typename?: 'Entry'; 55 | id: number; 56 | createdAt: number; 57 | commentCount: number; 58 | postedBy: { __typename?: 'User'; login: string; html_url: string }; 59 | comments: Array>; 60 | repository: { 61 | __typename?: 'Repository'; 62 | description?: Maybe; 63 | open_issues_count?: Maybe; 64 | stargazers_count: number; 65 | full_name: string; 66 | html_url: string; 67 | }; 68 | }>; 69 | }; 70 | 71 | export type CommentsPageCommentFragment = { 72 | __typename?: 'Comment'; 73 | id: number; 74 | createdAt: number; 75 | content: string; 76 | postedBy: { __typename?: 'User'; login: string; html_url: string }; 77 | }; 78 | 79 | export type CurrentUserForProfileQueryVariables = Exact<{ [key: string]: never }>; 80 | 81 | export type CurrentUserForProfileQuery = { 82 | __typename?: 'Query'; 83 | currentUser?: Maybe<{ __typename?: 'User'; login: string; avatar_url: string }>; 84 | }; 85 | 86 | export type FeedEntryFragment = { 87 | __typename?: 'Entry'; 88 | id: number; 89 | commentCount: number; 90 | repository: { 91 | __typename?: 'Repository'; 92 | full_name: string; 93 | html_url: string; 94 | owner?: Maybe<{ __typename?: 'User'; avatar_url: string }>; 95 | }; 96 | } & VoteButtonsFragment & 97 | RepoInfoFragment; 98 | 99 | export type FeedQueryVariables = Exact<{ 100 | type: FeedType; 101 | offset?: Maybe; 102 | limit?: Maybe; 103 | }>; 104 | 105 | export type FeedQuery = { 106 | __typename?: 'Query'; 107 | currentUser?: Maybe<{ __typename?: 'User'; login: string }>; 108 | feed?: Maybe>>; 109 | }; 110 | 111 | export type SubmitRepositoryMutationVariables = Exact<{ 112 | repoFullName: Scalars['String']; 113 | }>; 114 | 115 | export type SubmitRepositoryMutation = { 116 | __typename?: 'Mutation'; 117 | submitRepository?: Maybe<{ __typename?: 'Entry'; createdAt: number }>; 118 | }; 119 | 120 | export type RepoInfoFragment = { 121 | __typename?: 'Entry'; 122 | createdAt: number; 123 | repository: { 124 | __typename?: 'Repository'; 125 | description?: Maybe; 126 | stargazers_count: number; 127 | open_issues_count?: Maybe; 128 | }; 129 | postedBy: { __typename?: 'User'; html_url: string; login: string }; 130 | }; 131 | 132 | export type SubmitCommentMutationVariables = Exact<{ 133 | repoFullName: Scalars['String']; 134 | commentContent: Scalars['String']; 135 | }>; 136 | 137 | export type SubmitCommentMutation = { 138 | __typename?: 'Mutation'; 139 | submitComment?: Maybe<{ __typename?: 'Comment' } & CommentsPageCommentFragment>; 140 | }; 141 | 142 | export type VoteButtonsFragment = { 143 | __typename?: 'Entry'; 144 | score: number; 145 | vote: { __typename?: 'Vote'; vote_value: number }; 146 | }; 147 | 148 | export type VoteMutationVariables = Exact<{ 149 | repoFullName: Scalars['String']; 150 | type: VoteType; 151 | }>; 152 | 153 | export type VoteMutation = { 154 | __typename?: 'Mutation'; 155 | vote?: Maybe<{ __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } }>; 156 | }; 157 | -------------------------------------------------------------------------------- /dev-test/githunt/types.preResolveTypes.ts: -------------------------------------------------------------------------------- 1 | export type Maybe = T | null; 2 | export type Exact = { [K in keyof T]: T[K] }; 3 | /** All built-in and custom scalars, mapped to their actual values */ 4 | export type Scalars = { 5 | ID: string; 6 | String: string; 7 | Boolean: boolean; 8 | Int: number; 9 | Float: number; 10 | }; 11 | 12 | export type Query = { 13 | __typename?: 'Query'; 14 | /** A feed of repository submissions */ 15 | feed?: Maybe>>; 16 | /** A single entry */ 17 | entry?: Maybe; 18 | /** Return the currently logged in user, or null if nobody is logged in */ 19 | currentUser?: Maybe; 20 | }; 21 | 22 | export type QueryFeedArgs = { 23 | type: FeedType; 24 | offset?: Maybe; 25 | limit?: Maybe; 26 | }; 27 | 28 | export type QueryEntryArgs = { 29 | repoFullName: Scalars['String']; 30 | }; 31 | 32 | /** A list of options for the sort order of the feed */ 33 | export enum FeedType { 34 | /** Sort by a combination of freshness and score, using Reddit's algorithm */ 35 | Hot = 'HOT', 36 | /** Newest entries first */ 37 | New = 'NEW', 38 | /** Highest score entries first */ 39 | Top = 'TOP', 40 | } 41 | 42 | /** Information about a GitHub repository submitted to GitHunt */ 43 | export type Entry = { 44 | __typename?: 'Entry'; 45 | /** Information about the repository from GitHub */ 46 | repository: Repository; 47 | /** The GitHub user who submitted this entry */ 48 | postedBy: User; 49 | /** A timestamp of when the entry was submitted */ 50 | createdAt: Scalars['Float']; 51 | /** The score of this repository, upvotes - downvotes */ 52 | score: Scalars['Int']; 53 | /** The hot score of this repository */ 54 | hotScore: Scalars['Float']; 55 | /** Comments posted about this repository */ 56 | comments: Array>; 57 | /** The number of comments posted about this repository */ 58 | commentCount: Scalars['Int']; 59 | /** The SQL ID of this entry */ 60 | id: Scalars['Int']; 61 | /** XXX to be changed */ 62 | vote: Vote; 63 | }; 64 | 65 | /** Information about a GitHub repository submitted to GitHunt */ 66 | export type EntryCommentsArgs = { 67 | limit?: Maybe; 68 | offset?: Maybe; 69 | }; 70 | 71 | /** 72 | * A repository object from the GitHub API. This uses the exact field names returned by the 73 | * GitHub API for simplicity, even though the convention for GraphQL is usually to camel case. 74 | */ 75 | export type Repository = { 76 | __typename?: 'Repository'; 77 | /** Just the name of the repository, e.g. GitHunt-API */ 78 | name: Scalars['String']; 79 | /** The full name of the repository with the username, e.g. apollostack/GitHunt-API */ 80 | full_name: Scalars['String']; 81 | /** The description of the repository */ 82 | description?: Maybe; 83 | /** The link to the repository on GitHub */ 84 | html_url: Scalars['String']; 85 | /** The number of people who have starred this repository on GitHub */ 86 | stargazers_count: Scalars['Int']; 87 | /** The number of open issues on this repository on GitHub */ 88 | open_issues_count?: Maybe; 89 | /** The owner of this repository on GitHub, e.g. apollostack */ 90 | owner?: Maybe; 91 | }; 92 | 93 | /** A user object from the GitHub API. This uses the exact field names returned from the GitHub API. */ 94 | export type User = { 95 | __typename?: 'User'; 96 | /** The name of the user, e.g. apollostack */ 97 | login: Scalars['String']; 98 | /** The URL to a directly embeddable image for this user's avatar */ 99 | avatar_url: Scalars['String']; 100 | /** The URL of this user's GitHub page */ 101 | html_url: Scalars['String']; 102 | }; 103 | 104 | /** A comment about an entry, submitted by a user */ 105 | export type Comment = { 106 | __typename?: 'Comment'; 107 | /** The SQL ID of this entry */ 108 | id: Scalars['Int']; 109 | /** The GitHub user who posted the comment */ 110 | postedBy: User; 111 | /** A timestamp of when the comment was posted */ 112 | createdAt: Scalars['Float']; 113 | /** The text of the comment */ 114 | content: Scalars['String']; 115 | /** The repository which this comment is about */ 116 | repoName: Scalars['String']; 117 | }; 118 | 119 | /** XXX to be removed */ 120 | export type Vote = { 121 | __typename?: 'Vote'; 122 | vote_value: Scalars['Int']; 123 | }; 124 | 125 | export type Mutation = { 126 | __typename?: 'Mutation'; 127 | /** Submit a new repository, returns the new submission */ 128 | submitRepository?: Maybe; 129 | /** Vote on a repository submission, returns the submission that was voted on */ 130 | vote?: Maybe; 131 | /** Comment on a repository, returns the new comment */ 132 | submitComment?: Maybe; 133 | }; 134 | 135 | export type MutationSubmitRepositoryArgs = { 136 | repoFullName: Scalars['String']; 137 | }; 138 | 139 | export type MutationVoteArgs = { 140 | repoFullName: Scalars['String']; 141 | type: VoteType; 142 | }; 143 | 144 | export type MutationSubmitCommentArgs = { 145 | repoFullName: Scalars['String']; 146 | commentContent: Scalars['String']; 147 | }; 148 | 149 | /** The type of vote to record, when submitting a vote */ 150 | export enum VoteType { 151 | Up = 'UP', 152 | Down = 'DOWN', 153 | Cancel = 'CANCEL', 154 | } 155 | 156 | export type Subscription = { 157 | __typename?: 'Subscription'; 158 | /** Subscription fires on every comment added */ 159 | commentAdded?: Maybe; 160 | }; 161 | 162 | export type SubscriptionCommentAddedArgs = { 163 | repoFullName: Scalars['String']; 164 | }; 165 | 166 | export type OnCommentAddedSubscriptionVariables = Exact<{ 167 | repoFullName: Scalars['String']; 168 | }>; 169 | 170 | export type OnCommentAddedSubscription = { 171 | __typename?: 'Subscription'; 172 | commentAdded?: Maybe<{ 173 | __typename?: 'Comment'; 174 | id: number; 175 | createdAt: number; 176 | content: string; 177 | postedBy: { __typename?: 'User'; login: string; html_url: string }; 178 | }>; 179 | }; 180 | 181 | export type CommentQueryVariables = Exact<{ 182 | repoFullName: Scalars['String']; 183 | limit?: Maybe; 184 | offset?: Maybe; 185 | }>; 186 | 187 | export type CommentQuery = { 188 | __typename?: 'Query'; 189 | currentUser?: Maybe<{ __typename?: 'User'; login: string; html_url: string }>; 190 | entry?: Maybe<{ 191 | __typename?: 'Entry'; 192 | id: number; 193 | createdAt: number; 194 | commentCount: number; 195 | postedBy: { __typename?: 'User'; login: string; html_url: string }; 196 | comments: Array>; 197 | repository: { 198 | __typename?: 'Repository'; 199 | description?: Maybe; 200 | open_issues_count?: Maybe; 201 | stargazers_count: number; 202 | full_name: string; 203 | html_url: string; 204 | }; 205 | }>; 206 | }; 207 | 208 | export type CommentsPageCommentFragment = { 209 | __typename?: 'Comment'; 210 | id: number; 211 | createdAt: number; 212 | content: string; 213 | postedBy: { __typename?: 'User'; login: string; html_url: string }; 214 | }; 215 | 216 | export type CurrentUserForProfileQueryVariables = Exact<{ [key: string]: never }>; 217 | 218 | export type CurrentUserForProfileQuery = { 219 | __typename?: 'Query'; 220 | currentUser?: Maybe<{ __typename?: 'User'; login: string; avatar_url: string }>; 221 | }; 222 | 223 | export type FeedEntryFragment = { 224 | __typename?: 'Entry'; 225 | id: number; 226 | commentCount: number; 227 | repository: { 228 | __typename?: 'Repository'; 229 | full_name: string; 230 | html_url: string; 231 | owner?: Maybe<{ __typename?: 'User'; avatar_url: string }>; 232 | }; 233 | } & VoteButtonsFragment & 234 | RepoInfoFragment; 235 | 236 | export type FeedQueryVariables = Exact<{ 237 | type: FeedType; 238 | offset?: Maybe; 239 | limit?: Maybe; 240 | }>; 241 | 242 | export type FeedQuery = { 243 | __typename?: 'Query'; 244 | currentUser?: Maybe<{ __typename?: 'User'; login: string }>; 245 | feed?: Maybe>>; 246 | }; 247 | 248 | export type SubmitRepositoryMutationVariables = Exact<{ 249 | repoFullName: Scalars['String']; 250 | }>; 251 | 252 | export type SubmitRepositoryMutation = { 253 | __typename?: 'Mutation'; 254 | submitRepository?: Maybe<{ __typename?: 'Entry'; createdAt: number }>; 255 | }; 256 | 257 | export type RepoInfoFragment = { 258 | __typename?: 'Entry'; 259 | createdAt: number; 260 | repository: { 261 | __typename?: 'Repository'; 262 | description?: Maybe; 263 | stargazers_count: number; 264 | open_issues_count?: Maybe; 265 | }; 266 | postedBy: { __typename?: 'User'; html_url: string; login: string }; 267 | }; 268 | 269 | export type SubmitCommentMutationVariables = Exact<{ 270 | repoFullName: Scalars['String']; 271 | commentContent: Scalars['String']; 272 | }>; 273 | 274 | export type SubmitCommentMutation = { 275 | __typename?: 'Mutation'; 276 | submitComment?: Maybe<{ __typename?: 'Comment' } & CommentsPageCommentFragment>; 277 | }; 278 | 279 | export type VoteButtonsFragment = { 280 | __typename?: 'Entry'; 281 | score: number; 282 | vote: { __typename?: 'Vote'; vote_value: number }; 283 | }; 284 | 285 | export type VoteMutationVariables = Exact<{ 286 | repoFullName: Scalars['String']; 287 | type: VoteType; 288 | }>; 289 | 290 | export type VoteMutation = { 291 | __typename?: 'Mutation'; 292 | vote?: Maybe<{ __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } }>; 293 | }; 294 | -------------------------------------------------------------------------------- /dev-test/githunt/types.ts: -------------------------------------------------------------------------------- 1 | export type Maybe = T | null; 2 | export type Exact = { [K in keyof T]: T[K] }; 3 | /** All built-in and custom scalars, mapped to their actual values */ 4 | export type Scalars = { 5 | ID: string; 6 | String: string; 7 | Boolean: boolean; 8 | Int: number; 9 | Float: number; 10 | }; 11 | 12 | export type Query = { 13 | __typename?: 'Query'; 14 | /** A feed of repository submissions */ 15 | feed?: Maybe>>; 16 | /** A single entry */ 17 | entry?: Maybe; 18 | /** Return the currently logged in user, or null if nobody is logged in */ 19 | currentUser?: Maybe; 20 | }; 21 | 22 | export type QueryFeedArgs = { 23 | type: FeedType; 24 | offset?: Maybe; 25 | limit?: Maybe; 26 | }; 27 | 28 | export type QueryEntryArgs = { 29 | repoFullName: Scalars['String']; 30 | }; 31 | 32 | /** A list of options for the sort order of the feed */ 33 | export enum FeedType { 34 | /** Sort by a combination of freshness and score, using Reddit's algorithm */ 35 | Hot = 'HOT', 36 | /** Newest entries first */ 37 | New = 'NEW', 38 | /** Highest score entries first */ 39 | Top = 'TOP', 40 | } 41 | 42 | /** Information about a GitHub repository submitted to GitHunt */ 43 | export type Entry = { 44 | __typename?: 'Entry'; 45 | /** Information about the repository from GitHub */ 46 | repository: Repository; 47 | /** The GitHub user who submitted this entry */ 48 | postedBy: User; 49 | /** A timestamp of when the entry was submitted */ 50 | createdAt: Scalars['Float']; 51 | /** The score of this repository, upvotes - downvotes */ 52 | score: Scalars['Int']; 53 | /** The hot score of this repository */ 54 | hotScore: Scalars['Float']; 55 | /** Comments posted about this repository */ 56 | comments: Array>; 57 | /** The number of comments posted about this repository */ 58 | commentCount: Scalars['Int']; 59 | /** The SQL ID of this entry */ 60 | id: Scalars['Int']; 61 | /** XXX to be changed */ 62 | vote: Vote; 63 | }; 64 | 65 | /** Information about a GitHub repository submitted to GitHunt */ 66 | export type EntryCommentsArgs = { 67 | limit?: Maybe; 68 | offset?: Maybe; 69 | }; 70 | 71 | /** 72 | * A repository object from the GitHub API. This uses the exact field names returned by the 73 | * GitHub API for simplicity, even though the convention for GraphQL is usually to camel case. 74 | */ 75 | export type Repository = { 76 | __typename?: 'Repository'; 77 | /** Just the name of the repository, e.g. GitHunt-API */ 78 | name: Scalars['String']; 79 | /** The full name of the repository with the username, e.g. apollostack/GitHunt-API */ 80 | full_name: Scalars['String']; 81 | /** The description of the repository */ 82 | description?: Maybe; 83 | /** The link to the repository on GitHub */ 84 | html_url: Scalars['String']; 85 | /** The number of people who have starred this repository on GitHub */ 86 | stargazers_count: Scalars['Int']; 87 | /** The number of open issues on this repository on GitHub */ 88 | open_issues_count?: Maybe; 89 | /** The owner of this repository on GitHub, e.g. apollostack */ 90 | owner?: Maybe; 91 | }; 92 | 93 | /** A user object from the GitHub API. This uses the exact field names returned from the GitHub API. */ 94 | export type User = { 95 | __typename?: 'User'; 96 | /** The name of the user, e.g. apollostack */ 97 | login: Scalars['String']; 98 | /** The URL to a directly embeddable image for this user's avatar */ 99 | avatar_url: Scalars['String']; 100 | /** The URL of this user's GitHub page */ 101 | html_url: Scalars['String']; 102 | }; 103 | 104 | /** A comment about an entry, submitted by a user */ 105 | export type Comment = { 106 | __typename?: 'Comment'; 107 | /** The SQL ID of this entry */ 108 | id: Scalars['Int']; 109 | /** The GitHub user who posted the comment */ 110 | postedBy: User; 111 | /** A timestamp of when the comment was posted */ 112 | createdAt: Scalars['Float']; 113 | /** The text of the comment */ 114 | content: Scalars['String']; 115 | /** The repository which this comment is about */ 116 | repoName: Scalars['String']; 117 | }; 118 | 119 | /** XXX to be removed */ 120 | export type Vote = { 121 | __typename?: 'Vote'; 122 | vote_value: Scalars['Int']; 123 | }; 124 | 125 | export type Mutation = { 126 | __typename?: 'Mutation'; 127 | /** Submit a new repository, returns the new submission */ 128 | submitRepository?: Maybe; 129 | /** Vote on a repository submission, returns the submission that was voted on */ 130 | vote?: Maybe; 131 | /** Comment on a repository, returns the new comment */ 132 | submitComment?: Maybe; 133 | }; 134 | 135 | export type MutationSubmitRepositoryArgs = { 136 | repoFullName: Scalars['String']; 137 | }; 138 | 139 | export type MutationVoteArgs = { 140 | repoFullName: Scalars['String']; 141 | type: VoteType; 142 | }; 143 | 144 | export type MutationSubmitCommentArgs = { 145 | repoFullName: Scalars['String']; 146 | commentContent: Scalars['String']; 147 | }; 148 | 149 | /** The type of vote to record, when submitting a vote */ 150 | export enum VoteType { 151 | Up = 'UP', 152 | Down = 'DOWN', 153 | Cancel = 'CANCEL', 154 | } 155 | 156 | export type Subscription = { 157 | __typename?: 'Subscription'; 158 | /** Subscription fires on every comment added */ 159 | commentAdded?: Maybe; 160 | }; 161 | 162 | export type SubscriptionCommentAddedArgs = { 163 | repoFullName: Scalars['String']; 164 | }; 165 | 166 | export type OnCommentAddedSubscriptionVariables = Exact<{ 167 | repoFullName: Scalars['String']; 168 | }>; 169 | 170 | export type OnCommentAddedSubscription = { __typename?: 'Subscription' } & { 171 | commentAdded?: Maybe< 172 | { __typename?: 'Comment' } & Pick & { 173 | postedBy: { __typename?: 'User' } & Pick; 174 | } 175 | >; 176 | }; 177 | 178 | export type CommentQueryVariables = Exact<{ 179 | repoFullName: Scalars['String']; 180 | limit?: Maybe; 181 | offset?: Maybe; 182 | }>; 183 | 184 | export type CommentQuery = { __typename?: 'Query' } & { 185 | currentUser?: Maybe<{ __typename?: 'User' } & Pick>; 186 | entry?: Maybe< 187 | { __typename?: 'Entry' } & Pick & { 188 | postedBy: { __typename?: 'User' } & Pick; 189 | comments: Array>; 190 | repository: { __typename?: 'Repository' } & Pick< 191 | Repository, 192 | 'description' | 'open_issues_count' | 'stargazers_count' | 'full_name' | 'html_url' 193 | >; 194 | } 195 | >; 196 | }; 197 | 198 | export type CommentsPageCommentFragment = { __typename?: 'Comment' } & Pick & { 199 | postedBy: { __typename?: 'User' } & Pick; 200 | }; 201 | 202 | export type CurrentUserForProfileQueryVariables = Exact<{ [key: string]: never }>; 203 | 204 | export type CurrentUserForProfileQuery = { __typename?: 'Query' } & { 205 | currentUser?: Maybe<{ __typename?: 'User' } & Pick>; 206 | }; 207 | 208 | export type FeedEntryFragment = { __typename?: 'Entry' } & Pick & { 209 | repository: { __typename?: 'Repository' } & Pick & { 210 | owner?: Maybe<{ __typename?: 'User' } & Pick>; 211 | }; 212 | } & VoteButtonsFragment & 213 | RepoInfoFragment; 214 | 215 | export type FeedQueryVariables = Exact<{ 216 | type: FeedType; 217 | offset?: Maybe; 218 | limit?: Maybe; 219 | }>; 220 | 221 | export type FeedQuery = { __typename?: 'Query' } & { 222 | currentUser?: Maybe<{ __typename?: 'User' } & Pick>; 223 | feed?: Maybe>>; 224 | }; 225 | 226 | export type SubmitRepositoryMutationVariables = Exact<{ 227 | repoFullName: Scalars['String']; 228 | }>; 229 | 230 | export type SubmitRepositoryMutation = { __typename?: 'Mutation' } & { 231 | submitRepository?: Maybe<{ __typename?: 'Entry' } & Pick>; 232 | }; 233 | 234 | export type RepoInfoFragment = { __typename?: 'Entry' } & Pick & { 235 | repository: { __typename?: 'Repository' } & Pick< 236 | Repository, 237 | 'description' | 'stargazers_count' | 'open_issues_count' 238 | >; 239 | postedBy: { __typename?: 'User' } & Pick; 240 | }; 241 | 242 | export type SubmitCommentMutationVariables = Exact<{ 243 | repoFullName: Scalars['String']; 244 | commentContent: Scalars['String']; 245 | }>; 246 | 247 | export type SubmitCommentMutation = { __typename?: 'Mutation' } & { 248 | submitComment?: Maybe<{ __typename?: 'Comment' } & CommentsPageCommentFragment>; 249 | }; 250 | 251 | export type VoteButtonsFragment = { __typename?: 'Entry' } & Pick & { 252 | vote: { __typename?: 'Vote' } & Pick; 253 | }; 254 | 255 | export type VoteMutationVariables = Exact<{ 256 | repoFullName: Scalars['String']; 257 | type: VoteType; 258 | }>; 259 | 260 | export type VoteMutation = { __typename?: 'Mutation' } & { 261 | vote?: Maybe< 262 | { __typename?: 'Entry' } & Pick & { 263 | vote: { __typename?: 'Vote' } & Pick; 264 | } 265 | >; 266 | }; 267 | -------------------------------------------------------------------------------- /dev-test/githunt/vote-buttons.fragment.graphql: -------------------------------------------------------------------------------- 1 | fragment VoteButtons on Entry { 2 | score 3 | vote { 4 | vote_value 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /dev-test/githunt/vote.mutation.graphql: -------------------------------------------------------------------------------- 1 | mutation vote($repoFullName: String!, $type: VoteType!) { 2 | vote(repoFullName: $repoFullName, type: $type) { 3 | score 4 | id 5 | vote { 6 | vote_value 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /dev-test/setup.js: -------------------------------------------------------------------------------- 1 | process.on('unhandledRejection', (err) => { 2 | fail(err); 3 | }); -------------------------------------------------------------------------------- /dev-test/test-message/documents.ts: -------------------------------------------------------------------------------- 1 | import gql from 'graphql-tag'; 2 | 3 | // tslint:disable-next-line:variable-name 4 | export const GetMessages = gql` 5 | query GetMessages($tab: String!) { 6 | messages(tab: $tab) { 7 | id 8 | } 9 | } 10 | `; 11 | 12 | // tslint:disable-next-line:variable-name 13 | export const CreateMessage = gql` 14 | mutation CreateMessage($args: CreateMessageInput!) { 15 | createMessage(args: $args) { 16 | id 17 | } 18 | } 19 | `; 20 | 21 | // tslint:disable-next-line:variable-name 22 | export const Decline = gql` 23 | mutation Decline($id: ID!, $reason: String!) { 24 | decline(id: $id, reason: $reason) { 25 | id 26 | } 27 | } 28 | `; 29 | 30 | // tslint:disable-next-line:variable-name 31 | export const Approve = gql` 32 | mutation Approve($id: ID!) { 33 | approve(id: $id) { 34 | id 35 | } 36 | } 37 | `; 38 | 39 | // tslint:disable-next-line:variable-name 40 | export const Escalate = gql` 41 | mutation Escalate($id: ID!) { 42 | escalate(id: $id) { 43 | id 44 | } 45 | } 46 | `; 47 | -------------------------------------------------------------------------------- /dev-test/test-message/schema.graphql: -------------------------------------------------------------------------------- 1 | type Message { 2 | id: String! 3 | } 4 | 5 | type Query { 6 | messages(tab: String!): [Message] 7 | } 8 | 9 | input CreateMessageInput { 10 | description: String! 11 | } 12 | 13 | type Mutation { 14 | createMessage(args: CreateMessageInput!): Message 15 | approve(id: ID!): Message 16 | decline(id: ID!, reason: String!): Message 17 | escalate(id: ID!): Message 18 | } 19 | 20 | schema { 21 | query: Query 22 | mutation: Mutation 23 | } 24 | -------------------------------------------------------------------------------- /dev-test/test-message/types.tsx: -------------------------------------------------------------------------------- 1 | import * as Operations from './documents'; 2 | import * as Apollo from '@apollo/client'; 3 | export type Maybe = T | null; 4 | export type Exact = { [K in keyof T]: T[K] }; 5 | /** All built-in and custom scalars, mapped to their actual values */ 6 | export type Scalars = { 7 | ID: string; 8 | String: string; 9 | Boolean: boolean; 10 | Int: number; 11 | Float: number; 12 | }; 13 | 14 | export type Message = { 15 | __typename?: 'Message'; 16 | id: Scalars['String']; 17 | }; 18 | 19 | export type Query = { 20 | __typename?: 'Query'; 21 | messages?: Maybe>>; 22 | }; 23 | 24 | export type QueryMessagesArgs = { 25 | tab: Scalars['String']; 26 | }; 27 | 28 | export type CreateMessageInput = { 29 | description: Scalars['String']; 30 | }; 31 | 32 | export type Mutation = { 33 | __typename?: 'Mutation'; 34 | createMessage?: Maybe; 35 | approve?: Maybe; 36 | decline?: Maybe; 37 | escalate?: Maybe; 38 | }; 39 | 40 | export type MutationCreateMessageArgs = { 41 | args: CreateMessageInput; 42 | }; 43 | 44 | export type MutationApproveArgs = { 45 | id: Scalars['ID']; 46 | }; 47 | 48 | export type MutationDeclineArgs = { 49 | id: Scalars['ID']; 50 | reason: Scalars['String']; 51 | }; 52 | 53 | export type MutationEscalateArgs = { 54 | id: Scalars['ID']; 55 | }; 56 | 57 | export type GetMessagesQueryVariables = Exact<{ 58 | tab: Scalars['String']; 59 | }>; 60 | 61 | export type GetMessagesQuery = { __typename?: 'Query' } & { 62 | messages?: Maybe>>>; 63 | }; 64 | 65 | export type CreateMessageMutationVariables = Exact<{ 66 | args: CreateMessageInput; 67 | }>; 68 | 69 | export type CreateMessageMutation = { __typename?: 'Mutation' } & { 70 | createMessage?: Maybe<{ __typename?: 'Message' } & Pick>; 71 | }; 72 | 73 | export type DeclineMutationVariables = Exact<{ 74 | id: Scalars['ID']; 75 | reason: Scalars['String']; 76 | }>; 77 | 78 | export type DeclineMutation = { __typename?: 'Mutation' } & { 79 | decline?: Maybe<{ __typename?: 'Message' } & Pick>; 80 | }; 81 | 82 | export type ApproveMutationVariables = Exact<{ 83 | id: Scalars['ID']; 84 | }>; 85 | 86 | export type ApproveMutation = { __typename?: 'Mutation' } & { 87 | approve?: Maybe<{ __typename?: 'Message' } & Pick>; 88 | }; 89 | 90 | export type EscalateMutationVariables = Exact<{ 91 | id: Scalars['ID']; 92 | }>; 93 | 94 | export type EscalateMutation = { __typename?: 'Mutation' } & { 95 | escalate?: Maybe<{ __typename?: 'Message' } & Pick>; 96 | }; 97 | 98 | /** 99 | * __useGetMessagesQuery__ 100 | * 101 | * To run a query within a React component, call `useGetMessagesQuery` and pass it any options that fit your needs. 102 | * When your component renders, `useGetMessagesQuery` returns an object from Apollo Client that contains loading, error, and data properties 103 | * you can use to render your UI. 104 | * 105 | * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; 106 | * 107 | * @example 108 | * const { data, loading, error } = useGetMessagesQuery({ 109 | * variables: { 110 | * tab: // value for 'tab' 111 | * }, 112 | * }); 113 | */ 114 | export function useGetMessagesQuery( 115 | baseOptions?: Apollo.QueryHookOptions 116 | ) { 117 | return Apollo.useQuery(Operations.GetMessages, baseOptions); 118 | } 119 | export function useGetMessagesLazyQuery( 120 | baseOptions?: Apollo.LazyQueryHookOptions 121 | ) { 122 | return Apollo.useLazyQuery(Operations.GetMessages, baseOptions); 123 | } 124 | export type GetMessagesQueryHookResult = ReturnType; 125 | export type GetMessagesLazyQueryHookResult = ReturnType; 126 | export type GetMessagesQueryResult = Apollo.QueryResult; 127 | 128 | /** 129 | * __useCreateMessageMutation__ 130 | * 131 | * To run a mutation, you first call `useCreateMessageMutation` within a React component and pass it any options that fit your needs. 132 | * When your component renders, `useCreateMessageMutation` returns a tuple that includes: 133 | * - A mutate function that you can call at any time to execute the mutation 134 | * - An object with fields that represent the current status of the mutation's execution 135 | * 136 | * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; 137 | * 138 | * @example 139 | * const [createMessageMutation, { data, loading, error }] = useCreateMessageMutation({ 140 | * variables: { 141 | * args: // value for 'args' 142 | * }, 143 | * }); 144 | */ 145 | export function useCreateMessageMutation( 146 | baseOptions?: Apollo.MutationHookOptions 147 | ) { 148 | return Apollo.useMutation( 149 | Operations.CreateMessage, 150 | baseOptions 151 | ); 152 | } 153 | export type CreateMessageMutationHookResult = ReturnType; 154 | export type CreateMessageMutationResult = Apollo.MutationResult; 155 | export type CreateMessageMutationOptions = Apollo.BaseMutationOptions< 156 | CreateMessageMutation, 157 | CreateMessageMutationVariables 158 | >; 159 | 160 | /** 161 | * __useDeclineMutation__ 162 | * 163 | * To run a mutation, you first call `useDeclineMutation` within a React component and pass it any options that fit your needs. 164 | * When your component renders, `useDeclineMutation` returns a tuple that includes: 165 | * - A mutate function that you can call at any time to execute the mutation 166 | * - An object with fields that represent the current status of the mutation's execution 167 | * 168 | * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; 169 | * 170 | * @example 171 | * const [declineMutation, { data, loading, error }] = useDeclineMutation({ 172 | * variables: { 173 | * id: // value for 'id' 174 | * reason: // value for 'reason' 175 | * }, 176 | * }); 177 | */ 178 | export function useDeclineMutation( 179 | baseOptions?: Apollo.MutationHookOptions 180 | ) { 181 | return Apollo.useMutation(Operations.Decline, baseOptions); 182 | } 183 | export type DeclineMutationHookResult = ReturnType; 184 | export type DeclineMutationResult = Apollo.MutationResult; 185 | export type DeclineMutationOptions = Apollo.BaseMutationOptions; 186 | 187 | /** 188 | * __useApproveMutation__ 189 | * 190 | * To run a mutation, you first call `useApproveMutation` within a React component and pass it any options that fit your needs. 191 | * When your component renders, `useApproveMutation` returns a tuple that includes: 192 | * - A mutate function that you can call at any time to execute the mutation 193 | * - An object with fields that represent the current status of the mutation's execution 194 | * 195 | * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; 196 | * 197 | * @example 198 | * const [approveMutation, { data, loading, error }] = useApproveMutation({ 199 | * variables: { 200 | * id: // value for 'id' 201 | * }, 202 | * }); 203 | */ 204 | export function useApproveMutation( 205 | baseOptions?: Apollo.MutationHookOptions 206 | ) { 207 | return Apollo.useMutation(Operations.Approve, baseOptions); 208 | } 209 | export type ApproveMutationHookResult = ReturnType; 210 | export type ApproveMutationResult = Apollo.MutationResult; 211 | export type ApproveMutationOptions = Apollo.BaseMutationOptions; 212 | 213 | /** 214 | * __useEscalateMutation__ 215 | * 216 | * To run a mutation, you first call `useEscalateMutation` within a React component and pass it any options that fit your needs. 217 | * When your component renders, `useEscalateMutation` returns a tuple that includes: 218 | * - A mutate function that you can call at any time to execute the mutation 219 | * - An object with fields that represent the current status of the mutation's execution 220 | * 221 | * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; 222 | * 223 | * @example 224 | * const [escalateMutation, { data, loading, error }] = useEscalateMutation({ 225 | * variables: { 226 | * id: // value for 'id' 227 | * }, 228 | * }); 229 | */ 230 | export function useEscalateMutation( 231 | baseOptions?: Apollo.MutationHookOptions 232 | ) { 233 | return Apollo.useMutation(Operations.Escalate, baseOptions); 234 | } 235 | export type EscalateMutationHookResult = ReturnType; 236 | export type EscalateMutationResult = Apollo.MutationResult; 237 | export type EscalateMutationOptions = Apollo.BaseMutationOptions; 238 | -------------------------------------------------------------------------------- /dev-test/test-schema/env.types.ts: -------------------------------------------------------------------------------- 1 | export type Maybe = T | null; 2 | export type Exact = { [K in keyof T]: T[K] }; 3 | /** All built-in and custom scalars, mapped to their actual values */ 4 | export type Scalars = { 5 | ID: string; 6 | String: string; 7 | Boolean: boolean; 8 | Int: number; 9 | Float: number; 10 | }; 11 | 12 | export type User = { 13 | __typename?: 'User'; 14 | id: Scalars['Int']; 15 | name: Scalars['String']; 16 | email: Scalars['String']; 17 | }; 18 | 19 | export type Query = { 20 | __typename?: 'Query'; 21 | allUsers: Array>; 22 | userById?: Maybe; 23 | /** 24 | * Generates a new answer for th 25 | * guessing game 26 | */ 27 | answer: Array; 28 | testArr1?: Maybe>>; 29 | testArr2: Array>; 30 | testArr3: Array; 31 | }; 32 | 33 | export type QueryUserByIdArgs = { 34 | id: Scalars['Int']; 35 | }; 36 | -------------------------------------------------------------------------------- /dev-test/test-schema/flow-types.flow.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | 3 | import { type GraphQLResolveInfo } from 'graphql'; 4 | export type $RequireFields = $Diff & 5 | $ObjMapi(k: Key) => $NonMaybeType<$ElementType>>; 6 | /** All built-in and custom scalars, mapped to their actual values */ 7 | export type Scalars = {| 8 | ID: string, 9 | String: string, 10 | Boolean: boolean, 11 | Int: number, 12 | Float: number, 13 | |}; 14 | 15 | export type Query = {| 16 | __typename?: 'Query', 17 | allUsers: Array, 18 | userById?: ?User, 19 | |}; 20 | 21 | export type QueryUserByIdArgs = {| 22 | id: $ElementType, 23 | |}; 24 | 25 | export type User = {| 26 | __typename?: 'User', 27 | id: $ElementType, 28 | name: $ElementType, 29 | email: $ElementType, 30 | |}; 31 | 32 | export type Resolver = ( 33 | parent: Parent, 34 | args: Args, 35 | context: Context, 36 | info: GraphQLResolveInfo 37 | ) => Promise | Result; 38 | 39 | export type SubscriptionSubscribeFn = ( 40 | parent: Parent, 41 | args: Args, 42 | context: Context, 43 | info: GraphQLResolveInfo 44 | ) => AsyncIterator | Promise>; 45 | 46 | export type SubscriptionResolveFn = ( 47 | parent: Parent, 48 | args: Args, 49 | context: Context, 50 | info: GraphQLResolveInfo 51 | ) => Result | Promise; 52 | 53 | export interface SubscriptionSubscriberObject { 54 | subscribe: SubscriptionSubscribeFn<{ [key: Key]: Result }, Parent, Context, Args>; 55 | resolve?: SubscriptionResolveFn; 56 | } 57 | 58 | export interface SubscriptionResolverObject { 59 | subscribe: SubscriptionSubscribeFn; 60 | resolve: SubscriptionResolveFn; 61 | } 62 | 63 | export type SubscriptionObject = 64 | | SubscriptionSubscriberObject 65 | | SubscriptionResolverObject; 66 | 67 | export type SubscriptionResolver = 68 | | ((...args: Array) => SubscriptionObject) 69 | | SubscriptionObject; 70 | 71 | export type TypeResolveFn = ( 72 | parent: Parent, 73 | context: Context, 74 | info: GraphQLResolveInfo 75 | ) => ?Types | Promise; 76 | 77 | export type IsTypeOfResolverFn = ( 78 | obj: T, 79 | context: Context, 80 | info: GraphQLResolveInfo 81 | ) => boolean | Promise; 82 | 83 | export type NextResolverFn = () => Promise; 84 | 85 | export type DirectiveResolverFn = ( 86 | next: NextResolverFn, 87 | parent: Parent, 88 | args: Args, 89 | context: Context, 90 | info: GraphQLResolveInfo 91 | ) => Result | Promise; 92 | 93 | export type ResolverTypeWrapper = Promise | T; 94 | 95 | /** Mapping between all available schema types and the resolvers types */ 96 | export type ResolversTypes = { 97 | Query: ResolverTypeWrapper<{}>, 98 | Int: ResolverTypeWrapper<$ElementType>, 99 | User: ResolverTypeWrapper, 100 | String: ResolverTypeWrapper<$ElementType>, 101 | Boolean: ResolverTypeWrapper<$ElementType>, 102 | }; 103 | 104 | /** Mapping between all available schema types and the resolvers parents */ 105 | export type ResolversParentTypes = { 106 | Query: {}, 107 | Int: $ElementType, 108 | User: User, 109 | String: $ElementType, 110 | Boolean: $ElementType, 111 | }; 112 | 113 | export type QueryResolvers> = { 114 | allUsers?: Resolver>, ParentType, ContextType>, 115 | userById?: Resolver< 116 | ?$ElementType, 117 | ParentType, 118 | ContextType, 119 | $RequireFields 120 | >, 121 | }; 122 | 123 | export type UserResolvers> = { 124 | id?: Resolver<$ElementType, ParentType, ContextType>, 125 | name?: Resolver<$ElementType, ParentType, ContextType>, 126 | email?: Resolver<$ElementType, ParentType, ContextType>, 127 | __isTypeOf?: IsTypeOfResolverFn, 128 | }; 129 | 130 | export type Resolvers = { 131 | Query?: QueryResolvers, 132 | User?: UserResolvers, 133 | }; 134 | 135 | /** 136 | * @deprecated 137 | * Use "Resolvers" root object instead. If you wish to get "IResolvers", add "typesPrefix: I" to your config. 138 | */ 139 | export type IResolvers = Resolvers; 140 | -------------------------------------------------------------------------------- /dev-test/test-schema/local/schema-ast.js: -------------------------------------------------------------------------------- 1 | const schemaFormats = require('./schema-formats'); 2 | module.exports.schema = schemaFormats.schemaAst; 3 | -------------------------------------------------------------------------------- /dev-test/test-schema/local/schema-formats.js: -------------------------------------------------------------------------------- 1 | /** 2 | * There are four formats the schema can be in: 3 | * 1. GraphQLSchema object 4 | * 2. Text (the GraphQL schema language textual format) 5 | * 3. AST (the GraphQL schema language textual format parsed into an AST) 6 | * 7 | * This file imports the textual and introspection json files and 8 | * exports all four formats to be used in tests. 9 | */ 10 | 11 | const GraphQL = require('graphql'); 12 | const fs = require('fs'); 13 | const path = require('path'); 14 | const schemaText = fs.readFileSync(path.join(__dirname, 'schema.graphql'), 'utf8'); 15 | const schemaObject = GraphQL.buildSchema(schemaText); 16 | const schemaAst = GraphQL.parse(schemaText); 17 | 18 | module.exports.schemaText = schemaText; 19 | module.exports.schemaAst = schemaAst; 20 | module.exports.schemaObject = schemaObject; 21 | -------------------------------------------------------------------------------- /dev-test/test-schema/local/schema-object.js: -------------------------------------------------------------------------------- 1 | const schemaFormats = require('./schema-formats'); 2 | module.exports.schema = schemaFormats.schemaObject; 3 | -------------------------------------------------------------------------------- /dev-test/test-schema/local/schema-text.js: -------------------------------------------------------------------------------- 1 | const schemaFormats = require('./schema-formats'); 2 | module.exports.schema = schemaFormats.schemaText; 3 | -------------------------------------------------------------------------------- /dev-test/test-schema/local/schema.graphql: -------------------------------------------------------------------------------- 1 | type Post { 2 | id: Int! 3 | title: String! 4 | } 5 | 6 | type Query { 7 | allPosts: [Post]! 8 | } 9 | -------------------------------------------------------------------------------- /dev-test/test-schema/resolvers-federation.ts: -------------------------------------------------------------------------------- 1 | import { GraphQLResolveInfo } from 'graphql'; 2 | export type Maybe = T | null; 3 | export type Exact = { [K in keyof T]: T[K] }; 4 | /** All built-in and custom scalars, mapped to their actual values */ 5 | export type Scalars = { 6 | ID: string; 7 | String: string; 8 | Boolean: boolean; 9 | Int: number; 10 | Float: number; 11 | _FieldSet: any; 12 | }; 13 | 14 | export type Query = { 15 | __typename?: 'Query'; 16 | users?: Maybe>>; 17 | }; 18 | 19 | export type User = { 20 | __typename?: 'User'; 21 | id: Scalars['Int']; 22 | name: Scalars['String']; 23 | email: Scalars['String']; 24 | address?: Maybe
; 25 | }; 26 | 27 | export type Address = { 28 | __typename?: 'Address'; 29 | lines: Lines; 30 | city?: Maybe; 31 | state?: Maybe; 32 | }; 33 | 34 | export type Lines = { 35 | __typename?: 'Lines'; 36 | line1: Scalars['String']; 37 | line2?: Maybe; 38 | }; 39 | 40 | export type Book = { 41 | __typename?: 'Book'; 42 | id: Scalars['ID']; 43 | }; 44 | 45 | export type ResolverTypeWrapper = Promise | T; 46 | 47 | export type ReferenceResolver = ( 48 | reference: TReference, 49 | context: TContext, 50 | info: GraphQLResolveInfo 51 | ) => Promise | TResult; 52 | 53 | type ScalarCheck = S extends true ? T : NullableCheck; 54 | type NullableCheck = Maybe extends T ? Maybe, S>> : ListCheck; 55 | type ListCheck = T extends (infer U)[] ? NullableCheck[] : GraphQLRecursivePick; 56 | export type GraphQLRecursivePick = { [K in keyof T & keyof S]: ScalarCheck }; 57 | 58 | export type LegacyStitchingResolver = { 59 | fragment: string; 60 | resolve: ResolverFn; 61 | }; 62 | 63 | export type NewStitchingResolver = { 64 | selectionSet: string; 65 | resolve: ResolverFn; 66 | }; 67 | export type StitchingResolver = 68 | | LegacyStitchingResolver 69 | | NewStitchingResolver; 70 | export type Resolver = 71 | | ResolverFn 72 | | StitchingResolver; 73 | 74 | export type ResolverFn = ( 75 | parent: TParent, 76 | args: TArgs, 77 | context: TContext, 78 | info: GraphQLResolveInfo 79 | ) => Promise | TResult; 80 | 81 | export type SubscriptionSubscribeFn = ( 82 | parent: TParent, 83 | args: TArgs, 84 | context: TContext, 85 | info: GraphQLResolveInfo 86 | ) => AsyncIterator | Promise>; 87 | 88 | export type SubscriptionResolveFn = ( 89 | parent: TParent, 90 | args: TArgs, 91 | context: TContext, 92 | info: GraphQLResolveInfo 93 | ) => TResult | Promise; 94 | 95 | export interface SubscriptionSubscriberObject { 96 | subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; 97 | resolve?: SubscriptionResolveFn; 98 | } 99 | 100 | export interface SubscriptionResolverObject { 101 | subscribe: SubscriptionSubscribeFn; 102 | resolve: SubscriptionResolveFn; 103 | } 104 | 105 | export type SubscriptionObject = 106 | | SubscriptionSubscriberObject 107 | | SubscriptionResolverObject; 108 | 109 | export type SubscriptionResolver = 110 | | ((...args: any[]) => SubscriptionObject) 111 | | SubscriptionObject; 112 | 113 | export type TypeResolveFn = ( 114 | parent: TParent, 115 | context: TContext, 116 | info: GraphQLResolveInfo 117 | ) => Maybe | Promise>; 118 | 119 | export type IsTypeOfResolverFn = ( 120 | obj: T, 121 | context: TContext, 122 | info: GraphQLResolveInfo 123 | ) => boolean | Promise; 124 | 125 | export type NextResolverFn = () => Promise; 126 | 127 | export type DirectiveResolverFn = ( 128 | next: NextResolverFn, 129 | parent: TParent, 130 | args: TArgs, 131 | context: TContext, 132 | info: GraphQLResolveInfo 133 | ) => TResult | Promise; 134 | 135 | /** Mapping between all available schema types and the resolvers types */ 136 | export type ResolversTypes = { 137 | Query: ResolverTypeWrapper<{}>; 138 | User: ResolverTypeWrapper; 139 | Int: ResolverTypeWrapper; 140 | String: ResolverTypeWrapper; 141 | Address: ResolverTypeWrapper
; 142 | Lines: ResolverTypeWrapper; 143 | Book: ResolverTypeWrapper; 144 | ID: ResolverTypeWrapper; 145 | Boolean: ResolverTypeWrapper; 146 | }; 147 | 148 | /** Mapping between all available schema types and the resolvers parents */ 149 | export type ResolversParentTypes = { 150 | Query: {}; 151 | User: User; 152 | Int: Scalars['Int']; 153 | String: Scalars['String']; 154 | Address: Address; 155 | Lines: Lines; 156 | Book: Book; 157 | ID: Scalars['ID']; 158 | Boolean: Scalars['Boolean']; 159 | }; 160 | 161 | export type QueryResolvers< 162 | ContextType = any, 163 | ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'] 164 | > = { 165 | users?: Resolver>>, ParentType, ContextType>; 166 | }; 167 | 168 | export type UserResolvers< 169 | ContextType = any, 170 | ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'] 171 | > = { 172 | __resolveReference?: ReferenceResolver< 173 | Maybe, 174 | { __typename: 'User' } & ( 175 | | GraphQLRecursivePick 176 | | GraphQLRecursivePick 177 | ), 178 | ContextType 179 | >; 180 | 181 | email?: Resolver< 182 | ResolversTypes['String'], 183 | { __typename: 'User' } & ( 184 | | GraphQLRecursivePick 185 | | GraphQLRecursivePick 186 | ) & 187 | GraphQLRecursivePick, 188 | ContextType 189 | >; 190 | 191 | __isTypeOf?: IsTypeOfResolverFn; 192 | }; 193 | 194 | export type AddressResolvers< 195 | ContextType = any, 196 | ParentType extends ResolversParentTypes['Address'] = ResolversParentTypes['Address'] 197 | > = { 198 | lines?: Resolver; 199 | city?: Resolver, ParentType, ContextType>; 200 | state?: Resolver, ParentType, ContextType>; 201 | __isTypeOf?: IsTypeOfResolverFn; 202 | }; 203 | 204 | export type LinesResolvers< 205 | ContextType = any, 206 | ParentType extends ResolversParentTypes['Lines'] = ResolversParentTypes['Lines'] 207 | > = { 208 | line1?: Resolver; 209 | line2?: Resolver, ParentType, ContextType>; 210 | __isTypeOf?: IsTypeOfResolverFn; 211 | }; 212 | 213 | export type BookResolvers< 214 | ContextType = any, 215 | ParentType extends ResolversParentTypes['Book'] = ResolversParentTypes['Book'] 216 | > = { 217 | id?: Resolver; 218 | __isTypeOf?: IsTypeOfResolverFn; 219 | }; 220 | 221 | export type Resolvers = { 222 | Query?: QueryResolvers; 223 | User?: UserResolvers; 224 | Address?: AddressResolvers; 225 | Lines?: LinesResolvers; 226 | Book?: BookResolvers; 227 | }; 228 | 229 | /** 230 | * @deprecated 231 | * Use "Resolvers" root object instead. If you wish to get "IResolvers", add "typesPrefix: I" to your config. 232 | */ 233 | export type IResolvers = Resolvers; 234 | -------------------------------------------------------------------------------- /dev-test/test-schema/resolvers-root.ts: -------------------------------------------------------------------------------- 1 | import { GraphQLResolveInfo } from 'graphql'; 2 | export type Maybe = T | null; 3 | export type Exact = { [K in keyof T]: T[K] }; 4 | export type RequireFields = { [X in Exclude]?: T[X] } & 5 | { [P in K]-?: NonNullable }; 6 | /** All built-in and custom scalars, mapped to their actual values */ 7 | export type Scalars = { 8 | ID: string; 9 | String: string; 10 | Boolean: boolean; 11 | Int: number; 12 | Float: number; 13 | }; 14 | 15 | export type User = { 16 | __typename?: 'User'; 17 | id: Scalars['Int']; 18 | name: Scalars['String']; 19 | email: Scalars['String']; 20 | }; 21 | 22 | export type QueryRoot = { 23 | __typename?: 'QueryRoot'; 24 | allUsers: Array>; 25 | userById?: Maybe; 26 | answer: Array; 27 | }; 28 | 29 | export type QueryRootUserByIdArgs = { 30 | id: Scalars['Int']; 31 | }; 32 | 33 | export type SubscriptionRoot = { 34 | __typename?: 'SubscriptionRoot'; 35 | newUser?: Maybe; 36 | }; 37 | 38 | export type ResolverTypeWrapper = Promise | T; 39 | 40 | export type LegacyStitchingResolver = { 41 | fragment: string; 42 | resolve: ResolverFn; 43 | }; 44 | 45 | export type NewStitchingResolver = { 46 | selectionSet: string; 47 | resolve: ResolverFn; 48 | }; 49 | export type StitchingResolver = 50 | | LegacyStitchingResolver 51 | | NewStitchingResolver; 52 | export type Resolver = 53 | | ResolverFn 54 | | StitchingResolver; 55 | 56 | export type ResolverFn = ( 57 | parent: TParent, 58 | args: TArgs, 59 | context: TContext, 60 | info: GraphQLResolveInfo 61 | ) => Promise | TResult; 62 | 63 | export type SubscriptionSubscribeFn = ( 64 | parent: TParent, 65 | args: TArgs, 66 | context: TContext, 67 | info: GraphQLResolveInfo 68 | ) => AsyncIterator | Promise>; 69 | 70 | export type SubscriptionResolveFn = ( 71 | parent: TParent, 72 | args: TArgs, 73 | context: TContext, 74 | info: GraphQLResolveInfo 75 | ) => TResult | Promise; 76 | 77 | export interface SubscriptionSubscriberObject { 78 | subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; 79 | resolve?: SubscriptionResolveFn; 80 | } 81 | 82 | export interface SubscriptionResolverObject { 83 | subscribe: SubscriptionSubscribeFn; 84 | resolve: SubscriptionResolveFn; 85 | } 86 | 87 | export type SubscriptionObject = 88 | | SubscriptionSubscriberObject 89 | | SubscriptionResolverObject; 90 | 91 | export type SubscriptionResolver = 92 | | ((...args: any[]) => SubscriptionObject) 93 | | SubscriptionObject; 94 | 95 | export type TypeResolveFn = ( 96 | parent: TParent, 97 | context: TContext, 98 | info: GraphQLResolveInfo 99 | ) => Maybe | Promise>; 100 | 101 | export type IsTypeOfResolverFn = ( 102 | obj: T, 103 | context: TContext, 104 | info: GraphQLResolveInfo 105 | ) => boolean | Promise; 106 | 107 | export type NextResolverFn = () => Promise; 108 | 109 | export type DirectiveResolverFn = ( 110 | next: NextResolverFn, 111 | parent: TParent, 112 | args: TArgs, 113 | context: TContext, 114 | info: GraphQLResolveInfo 115 | ) => TResult | Promise; 116 | 117 | /** Mapping between all available schema types and the resolvers types */ 118 | export type ResolversTypes = { 119 | User: ResolverTypeWrapper; 120 | Int: ResolverTypeWrapper; 121 | String: ResolverTypeWrapper; 122 | QueryRoot: ResolverTypeWrapper<{}>; 123 | SubscriptionRoot: ResolverTypeWrapper<{}>; 124 | Boolean: ResolverTypeWrapper; 125 | }; 126 | 127 | /** Mapping between all available schema types and the resolvers parents */ 128 | export type ResolversParentTypes = { 129 | User: User; 130 | Int: Scalars['Int']; 131 | String: Scalars['String']; 132 | QueryRoot: {}; 133 | SubscriptionRoot: {}; 134 | Boolean: Scalars['Boolean']; 135 | }; 136 | 137 | export type UserResolvers< 138 | ContextType = any, 139 | ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'] 140 | > = { 141 | id?: Resolver; 142 | name?: Resolver; 143 | email?: Resolver; 144 | __isTypeOf?: IsTypeOfResolverFn; 145 | }; 146 | 147 | export type QueryRootResolvers< 148 | ContextType = any, 149 | ParentType extends ResolversParentTypes['QueryRoot'] = ResolversParentTypes['QueryRoot'] 150 | > = { 151 | allUsers?: Resolver>, ParentType, ContextType>; 152 | userById?: Resolver< 153 | Maybe, 154 | ParentType, 155 | ContextType, 156 | RequireFields 157 | >; 158 | answer?: Resolver, ParentType, ContextType>; 159 | }; 160 | 161 | export type SubscriptionRootResolvers< 162 | ContextType = any, 163 | ParentType extends ResolversParentTypes['SubscriptionRoot'] = ResolversParentTypes['SubscriptionRoot'] 164 | > = { 165 | newUser?: SubscriptionResolver, 'newUser', ParentType, ContextType>; 166 | }; 167 | 168 | export type Resolvers = { 169 | User?: UserResolvers; 170 | QueryRoot?: QueryRootResolvers; 171 | SubscriptionRoot?: SubscriptionRootResolvers; 172 | }; 173 | 174 | /** 175 | * @deprecated 176 | * Use "Resolvers" root object instead. If you wish to get "IResolvers", add "typesPrefix: I" to your config. 177 | */ 178 | export type IResolvers = Resolvers; 179 | -------------------------------------------------------------------------------- /dev-test/test-schema/resolvers-types.ts: -------------------------------------------------------------------------------- 1 | import { GraphQLResolveInfo } from 'graphql'; 2 | export type Maybe = T | null; 3 | export type Exact = { [K in keyof T]: T[K] }; 4 | export type RequireFields = { [X in Exclude]?: T[X] } & 5 | { [P in K]-?: NonNullable }; 6 | /** All built-in and custom scalars, mapped to their actual values */ 7 | export type Scalars = { 8 | ID: string; 9 | String: string; 10 | Boolean: boolean; 11 | Int: number; 12 | Float: number; 13 | }; 14 | 15 | export type User = { 16 | __typename?: 'User'; 17 | id: Scalars['Int']; 18 | name: Scalars['String']; 19 | email: Scalars['String']; 20 | }; 21 | 22 | export type Query = { 23 | __typename?: 'Query'; 24 | allUsers: Array>; 25 | userById?: Maybe; 26 | /** 27 | * Generates a new answer for th 28 | * guessing game 29 | */ 30 | answer: Array; 31 | testArr1?: Maybe>>; 32 | testArr2: Array>; 33 | testArr3: Array; 34 | }; 35 | 36 | export type QueryUserByIdArgs = { 37 | id: Scalars['Int']; 38 | }; 39 | 40 | export type ResolverTypeWrapper = Promise | T; 41 | 42 | export type LegacyStitchingResolver = { 43 | fragment: string; 44 | resolve: ResolverFn; 45 | }; 46 | 47 | export type NewStitchingResolver = { 48 | selectionSet: string; 49 | resolve: ResolverFn; 50 | }; 51 | export type StitchingResolver = 52 | | LegacyStitchingResolver 53 | | NewStitchingResolver; 54 | export type Resolver = 55 | | ResolverFn 56 | | StitchingResolver; 57 | 58 | export type ResolverFn = ( 59 | parent: TParent, 60 | args: TArgs, 61 | context: TContext, 62 | info: GraphQLResolveInfo 63 | ) => Promise | TResult; 64 | 65 | export type SubscriptionSubscribeFn = ( 66 | parent: TParent, 67 | args: TArgs, 68 | context: TContext, 69 | info: GraphQLResolveInfo 70 | ) => AsyncIterator | Promise>; 71 | 72 | export type SubscriptionResolveFn = ( 73 | parent: TParent, 74 | args: TArgs, 75 | context: TContext, 76 | info: GraphQLResolveInfo 77 | ) => TResult | Promise; 78 | 79 | export interface SubscriptionSubscriberObject { 80 | subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; 81 | resolve?: SubscriptionResolveFn; 82 | } 83 | 84 | export interface SubscriptionResolverObject { 85 | subscribe: SubscriptionSubscribeFn; 86 | resolve: SubscriptionResolveFn; 87 | } 88 | 89 | export type SubscriptionObject = 90 | | SubscriptionSubscriberObject 91 | | SubscriptionResolverObject; 92 | 93 | export type SubscriptionResolver = 94 | | ((...args: any[]) => SubscriptionObject) 95 | | SubscriptionObject; 96 | 97 | export type TypeResolveFn = ( 98 | parent: TParent, 99 | context: TContext, 100 | info: GraphQLResolveInfo 101 | ) => Maybe | Promise>; 102 | 103 | export type IsTypeOfResolverFn = ( 104 | obj: T, 105 | context: TContext, 106 | info: GraphQLResolveInfo 107 | ) => boolean | Promise; 108 | 109 | export type NextResolverFn = () => Promise; 110 | 111 | export type DirectiveResolverFn = ( 112 | next: NextResolverFn, 113 | parent: TParent, 114 | args: TArgs, 115 | context: TContext, 116 | info: GraphQLResolveInfo 117 | ) => TResult | Promise; 118 | 119 | /** Mapping between all available schema types and the resolvers types */ 120 | export type ResolversTypes = { 121 | User: ResolverTypeWrapper; 122 | Int: ResolverTypeWrapper; 123 | String: ResolverTypeWrapper; 124 | Query: ResolverTypeWrapper<{}>; 125 | Boolean: ResolverTypeWrapper; 126 | }; 127 | 128 | /** Mapping between all available schema types and the resolvers parents */ 129 | export type ResolversParentTypes = { 130 | User: User; 131 | Int: Scalars['Int']; 132 | String: Scalars['String']; 133 | Query: {}; 134 | Boolean: Scalars['Boolean']; 135 | }; 136 | 137 | export type UserResolvers< 138 | ContextType = any, 139 | ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'] 140 | > = { 141 | id?: Resolver; 142 | name?: Resolver; 143 | email?: Resolver; 144 | __isTypeOf?: IsTypeOfResolverFn; 145 | }; 146 | 147 | export type QueryResolvers< 148 | ContextType = any, 149 | ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'] 150 | > = { 151 | allUsers?: Resolver>, ParentType, ContextType>; 152 | userById?: Resolver, ParentType, ContextType, RequireFields>; 153 | answer?: Resolver, ParentType, ContextType>; 154 | testArr1?: Resolver>>, ParentType, ContextType>; 155 | testArr2?: Resolver>, ParentType, ContextType>; 156 | testArr3?: Resolver, ParentType, ContextType>; 157 | }; 158 | 159 | export type Resolvers = { 160 | User?: UserResolvers; 161 | Query?: QueryResolvers; 162 | }; 163 | 164 | /** 165 | * @deprecated 166 | * Use "Resolvers" root object instead. If you wish to get "IResolvers", add "typesPrefix: I" to your config. 167 | */ 168 | export type IResolvers = Resolvers; 169 | -------------------------------------------------------------------------------- /dev-test/test-schema/schema-ast.js: -------------------------------------------------------------------------------- 1 | const schemaFormats = require("./schema-formats"); 2 | module.exports.schema = schemaFormats.schemaAst; 3 | -------------------------------------------------------------------------------- /dev-test/test-schema/schema-federation.graphql: -------------------------------------------------------------------------------- 1 | extend type Query { 2 | users: [User] 3 | } 4 | 5 | extend type User @key(fields: "id") @key(fields: "name") { 6 | id: Int! @external 7 | name: String! @external 8 | email: String! 9 | @requires( 10 | fields: """ 11 | address(works: "with params!") { city lines { line2 } } 12 | """ 13 | ) 14 | address: Address @external 15 | } 16 | 17 | extend type Address { 18 | lines: Lines! 19 | city: String 20 | state: String 21 | } 22 | 23 | extend type Lines { 24 | line1: String! 25 | line2: String 26 | } 27 | 28 | type Book { 29 | id: ID! 30 | } 31 | -------------------------------------------------------------------------------- /dev-test/test-schema/schema-formats.js: -------------------------------------------------------------------------------- 1 | /** 2 | * There are four formats the schema can be in: 3 | * 1. GraphQLSchema object 4 | * 2. Text (the GraphQL schema language textual format) 5 | * 3. AST (the GraphQL schema language textual format parsed into an AST) 6 | * 4. Introspection JSON (result returned by introspection query) 7 | * 8 | * This file imports the textual and introspection json files and 9 | * exports all four formats to be used in tests. 10 | */ 11 | 12 | const GraphQL = require("graphql"); 13 | const fs = require('fs'); 14 | const path = require('path'); 15 | const schemaText = fs.readFileSync(path.join(__dirname, "schema.graphql"), 'utf8'); 16 | const schemaObject = new GraphQL.GraphQLSchema({ 17 | query: new GraphQL.GraphQLObjectType({ 18 | name: 'Query', 19 | fields: { 20 | foo: { 21 | type: new GraphQL.GraphQLEnumType({ 22 | name: 'Foo', 23 | values: { 24 | BAR: { 25 | value: 'QUX', 26 | } 27 | } 28 | }) 29 | } 30 | } 31 | }) 32 | }); 33 | const schemaAst = GraphQL.parse(schemaText); 34 | const schemaJson = require("./schema.json"); 35 | module.exports.schemaText = schemaText; 36 | module.exports.schemaAst = schemaAst; 37 | module.exports.schemaObject = schemaObject; 38 | module.exports.schemaJson = schemaJson; 39 | -------------------------------------------------------------------------------- /dev-test/test-schema/schema-json.js: -------------------------------------------------------------------------------- 1 | const schemaFormats = require("./schema-formats"); 2 | module.exports.schema = schemaFormats.schemaJson; 3 | -------------------------------------------------------------------------------- /dev-test/test-schema/schema-object.js: -------------------------------------------------------------------------------- 1 | const schemaFormats = require("./schema-formats"); 2 | module.exports.schema = schemaFormats.schemaObject; 3 | -------------------------------------------------------------------------------- /dev-test/test-schema/schema-text.js: -------------------------------------------------------------------------------- 1 | const schemaFormats = require("./schema-formats"); 2 | module.exports.schema = schemaFormats.schemaText; 3 | -------------------------------------------------------------------------------- /dev-test/test-schema/schema-with-imports.graphql: -------------------------------------------------------------------------------- 1 | # import User from './schema.graphql' 2 | 3 | type Query { 4 | allUsers: [User]! 5 | userById(id: Int!): User 6 | 7 | # Generates a new answer for the guessing game 8 | answer: [Int!]! 9 | } 10 | -------------------------------------------------------------------------------- /dev-test/test-schema/schema-with-root.graphql: -------------------------------------------------------------------------------- 1 | type User { 2 | id: Int! 3 | name: String! 4 | email: String! 5 | } 6 | 7 | type QueryRoot { 8 | allUsers: [User]! 9 | userById(id: Int!): User 10 | 11 | # Generates a new answer for the guessing game 12 | answer: [Int!]! 13 | } 14 | 15 | type SubscriptionRoot { 16 | newUser: User 17 | } 18 | 19 | schema { 20 | query: QueryRoot 21 | subscription: SubscriptionRoot 22 | } 23 | -------------------------------------------------------------------------------- /dev-test/test-schema/schema.graphql: -------------------------------------------------------------------------------- 1 | type User { 2 | id: Int! 3 | name: String! 4 | email: String! 5 | } 6 | 7 | type Query { 8 | allUsers: [User]! 9 | userById(id: Int!): User 10 | 11 | """ 12 | Generates a new answer for th 13 | guessing game 14 | """ 15 | answer: [Int!]! 16 | testArr1: [String] 17 | testArr2: [String]! 18 | testArr3: [String!]! 19 | } 20 | -------------------------------------------------------------------------------- /dev-test/test-schema/types.preResolveTypes.onlyOperationTypes.ts: -------------------------------------------------------------------------------- 1 | export type Maybe = T | null; 2 | export type Exact = { [K in keyof T]: T[K] }; 3 | /** All built-in and custom scalars, mapped to their actual values */ 4 | export type Scalars = { 5 | ID: string; 6 | String: string; 7 | Boolean: boolean; 8 | Int: number; 9 | Float: number; 10 | }; 11 | 12 | export type TestQueryVariables = Exact<{ [key: string]: never }>; 13 | 14 | export type TestQuery = { 15 | __typename?: 'Query'; 16 | testArr1?: Maybe>>; 17 | testArr2: Array>; 18 | testArr3: Array; 19 | }; 20 | -------------------------------------------------------------------------------- /dev-test/test-schema/types.preResolveTypes.ts: -------------------------------------------------------------------------------- 1 | export type Maybe = T | null; 2 | export type Exact = { [K in keyof T]: T[K] }; 3 | /** All built-in and custom scalars, mapped to their actual values */ 4 | export type Scalars = { 5 | ID: string; 6 | String: string; 7 | Boolean: boolean; 8 | Int: number; 9 | Float: number; 10 | }; 11 | 12 | export type User = { 13 | __typename?: 'User'; 14 | id: Scalars['Int']; 15 | name: Scalars['String']; 16 | email: Scalars['String']; 17 | }; 18 | 19 | export type Query = { 20 | __typename?: 'Query'; 21 | allUsers: Array>; 22 | userById?: Maybe; 23 | /** 24 | * Generates a new answer for th 25 | * guessing game 26 | */ 27 | answer: Array; 28 | testArr1?: Maybe>>; 29 | testArr2: Array>; 30 | testArr3: Array; 31 | }; 32 | 33 | export type QueryUserByIdArgs = { 34 | id: Scalars['Int']; 35 | }; 36 | 37 | export type TestQueryVariables = Exact<{ [key: string]: never }>; 38 | 39 | export type TestQuery = { 40 | __typename?: 'Query'; 41 | testArr1?: Maybe>>; 42 | testArr2: Array>; 43 | testArr3: Array; 44 | }; 45 | -------------------------------------------------------------------------------- /dev-test/test-schema/typings.avoidOptionals.ts: -------------------------------------------------------------------------------- 1 | export type Maybe = T | null; 2 | export type Exact = { [K in keyof T]: T[K] }; 3 | /** All built-in and custom scalars, mapped to their actual values */ 4 | export type Scalars = { 5 | ID: string; 6 | String: string; 7 | Boolean: boolean; 8 | Int: number; 9 | Float: number; 10 | }; 11 | 12 | export type Query = { 13 | __typename?: 'Query'; 14 | allUsers: Array>; 15 | userById: Maybe; 16 | }; 17 | 18 | export type QueryUserByIdArgs = { 19 | id: Scalars['Int']; 20 | }; 21 | 22 | export type User = { 23 | __typename?: 'User'; 24 | id: Scalars['Int']; 25 | name: Scalars['String']; 26 | email: Scalars['String']; 27 | }; 28 | -------------------------------------------------------------------------------- /dev-test/test-schema/typings.enum.ts: -------------------------------------------------------------------------------- 1 | export type Maybe = T | null; 2 | export type Exact = { [K in keyof T]: T[K] }; 3 | /** All built-in and custom scalars, mapped to their actual values */ 4 | export type Scalars = { 5 | ID: string; 6 | String: string; 7 | Boolean: boolean; 8 | Int: number; 9 | Float: number; 10 | }; 11 | 12 | export type Query = { 13 | __typename?: 'Query'; 14 | foo?: Maybe; 15 | }; 16 | 17 | export enum Foo { 18 | Bar = 'QUX', 19 | } 20 | -------------------------------------------------------------------------------- /dev-test/test-schema/typings.immutableTypes.ts: -------------------------------------------------------------------------------- 1 | export type Maybe = T | null; 2 | export type Exact = { [K in keyof T]: T[K] }; 3 | /** All built-in and custom scalars, mapped to their actual values */ 4 | export type Scalars = { 5 | ID: string; 6 | String: string; 7 | Boolean: boolean; 8 | Int: number; 9 | Float: number; 10 | }; 11 | 12 | export type Query = { 13 | __typename?: 'Query'; 14 | allUsers: Array>; 15 | userById?: Maybe; 16 | }; 17 | 18 | export type QueryUserByIdArgs = { 19 | id: Scalars['Int']; 20 | }; 21 | 22 | export type User = { 23 | __typename?: 'User'; 24 | id: Scalars['Int']; 25 | name: Scalars['String']; 26 | email: Scalars['String']; 27 | }; 28 | -------------------------------------------------------------------------------- /dev-test/test-schema/typings.ts: -------------------------------------------------------------------------------- 1 | import { GraphQLResolveInfo } from 'graphql'; 2 | export type Maybe = T | null; 3 | export type Exact = { [K in keyof T]: T[K] }; 4 | export type RequireFields = { [X in Exclude]?: T[X] } & 5 | { [P in K]-?: NonNullable }; 6 | /** All built-in and custom scalars, mapped to their actual values */ 7 | export type Scalars = { 8 | ID: string; 9 | String: string; 10 | Boolean: boolean; 11 | Int: number; 12 | Float: number; 13 | }; 14 | 15 | export type Query = { 16 | __typename?: 'Query'; 17 | allUsers: Array>; 18 | userById?: Maybe; 19 | }; 20 | 21 | export type QueryUserByIdArgs = { 22 | id: Scalars['Int']; 23 | }; 24 | 25 | export type User = { 26 | __typename?: 'User'; 27 | id: Scalars['Int']; 28 | name: Scalars['String']; 29 | email: Scalars['String']; 30 | }; 31 | 32 | export type ResolverTypeWrapper = Promise | T; 33 | 34 | export type LegacyStitchingResolver = { 35 | fragment: string; 36 | resolve: ResolverFn; 37 | }; 38 | 39 | export type NewStitchingResolver = { 40 | selectionSet: string; 41 | resolve: ResolverFn; 42 | }; 43 | export type StitchingResolver = 44 | | LegacyStitchingResolver 45 | | NewStitchingResolver; 46 | export type Resolver = 47 | | ResolverFn 48 | | StitchingResolver; 49 | 50 | export type ResolverFn = ( 51 | parent: TParent, 52 | args: TArgs, 53 | context: TContext, 54 | info: GraphQLResolveInfo 55 | ) => Promise | TResult; 56 | 57 | export type SubscriptionSubscribeFn = ( 58 | parent: TParent, 59 | args: TArgs, 60 | context: TContext, 61 | info: GraphQLResolveInfo 62 | ) => AsyncIterator | Promise>; 63 | 64 | export type SubscriptionResolveFn = ( 65 | parent: TParent, 66 | args: TArgs, 67 | context: TContext, 68 | info: GraphQLResolveInfo 69 | ) => TResult | Promise; 70 | 71 | export interface SubscriptionSubscriberObject { 72 | subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; 73 | resolve?: SubscriptionResolveFn; 74 | } 75 | 76 | export interface SubscriptionResolverObject { 77 | subscribe: SubscriptionSubscribeFn; 78 | resolve: SubscriptionResolveFn; 79 | } 80 | 81 | export type SubscriptionObject = 82 | | SubscriptionSubscriberObject 83 | | SubscriptionResolverObject; 84 | 85 | export type SubscriptionResolver = 86 | | ((...args: any[]) => SubscriptionObject) 87 | | SubscriptionObject; 88 | 89 | export type TypeResolveFn = ( 90 | parent: TParent, 91 | context: TContext, 92 | info: GraphQLResolveInfo 93 | ) => Maybe | Promise>; 94 | 95 | export type IsTypeOfResolverFn = ( 96 | obj: T, 97 | context: TContext, 98 | info: GraphQLResolveInfo 99 | ) => boolean | Promise; 100 | 101 | export type NextResolverFn = () => Promise; 102 | 103 | export type DirectiveResolverFn = ( 104 | next: NextResolverFn, 105 | parent: TParent, 106 | args: TArgs, 107 | context: TContext, 108 | info: GraphQLResolveInfo 109 | ) => TResult | Promise; 110 | 111 | /** Mapping between all available schema types and the resolvers types */ 112 | export type ResolversTypes = { 113 | Query: ResolverTypeWrapper<{}>; 114 | Int: ResolverTypeWrapper; 115 | User: ResolverTypeWrapper; 116 | String: ResolverTypeWrapper; 117 | Boolean: ResolverTypeWrapper; 118 | }; 119 | 120 | /** Mapping between all available schema types and the resolvers parents */ 121 | export type ResolversParentTypes = { 122 | Query: {}; 123 | Int: Scalars['Int']; 124 | User: User; 125 | String: Scalars['String']; 126 | Boolean: Scalars['Boolean']; 127 | }; 128 | 129 | export type QueryResolvers< 130 | ContextType = any, 131 | ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'] 132 | > = { 133 | allUsers?: Resolver>, ParentType, ContextType>; 134 | userById?: Resolver, ParentType, ContextType, RequireFields>; 135 | }; 136 | 137 | export type UserResolvers< 138 | ContextType = any, 139 | ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'] 140 | > = { 141 | id?: Resolver; 142 | name?: Resolver; 143 | email?: Resolver; 144 | __isTypeOf?: IsTypeOfResolverFn; 145 | }; 146 | 147 | export type Resolvers = { 148 | Query?: QueryResolvers; 149 | User?: UserResolvers; 150 | }; 151 | 152 | /** 153 | * @deprecated 154 | * Use "Resolvers" root object instead. If you wish to get "IResolvers", add "typesPrefix: I" to your config. 155 | */ 156 | export type IResolvers = Resolvers; 157 | -------------------------------------------------------------------------------- /dev-test/test-schema/typings.wrapped.ts: -------------------------------------------------------------------------------- 1 | declare namespace GraphQL { 2 | export type Maybe = T | null; 3 | export type Exact = { [K in keyof T]: T[K] }; 4 | /** All built-in and custom scalars, mapped to their actual values */ 5 | export type Scalars = { 6 | ID: string; 7 | String: string; 8 | Boolean: boolean; 9 | Int: number; 10 | Float: number; 11 | }; 12 | 13 | export type Query = { 14 | __typename?: 'Query'; 15 | allUsers: Array>; 16 | userById?: Maybe; 17 | }; 18 | 19 | export type QueryUserByIdArgs = { 20 | id: Scalars['Int']; 21 | }; 22 | 23 | export type User = { 24 | __typename?: 'User'; 25 | id: Scalars['Int']; 26 | name: Scalars['String']; 27 | email: Scalars['String']; 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /dev-test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "esModuleInterop": true, 4 | "lib": ["esnext"], 5 | "jsx": "react", 6 | "jsxFactory": "React.createElement", 7 | "skipLibCheck": true, 8 | "strict": true, 9 | "noImplicitAny": true, 10 | "noImplicitThis": true, 11 | "alwaysStrict": true, 12 | "noImplicitReturns": true, 13 | "noUnusedLocals": true, 14 | "noUnusedParameters": true, 15 | "experimentalDecorators": true 16 | }, 17 | "include": ["**/*.ts", "**/*.tsx"] 18 | } 19 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | const { resolve } = require('path') 2 | const { pathsToModuleNameMapper } = require('ts-jest') 3 | 4 | const pkg = require('./package.json') 5 | const tsconfig = require('./tsconfig.json') 6 | const CI = !!process.env.CI 7 | 8 | module.exports = () => { 9 | return { 10 | displayName: pkg.name, 11 | rootDir: __dirname, 12 | preset: 'ts-jest', 13 | testEnvironment: 'node', 14 | restoreMocks: true, 15 | reporters: ['default'], 16 | modulePathIgnorePatterns: ['dist'], 17 | moduleNameMapper: pathsToModuleNameMapper( 18 | tsconfig.compilerOptions.paths || [], 19 | { 20 | prefix: `./`, 21 | } 22 | ), 23 | cacheDirectory: resolve( 24 | __dirname, 25 | `${CI ? '' : 'node_modules/'}.cache/jest` 26 | ), 27 | setupFiles: [`${__dirname}/dev-test/setup.js`], 28 | collectCoverage: false, 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "graphql-codegen-plugin-typescript-swr", 3 | "version": "0.8.5", 4 | "description": "A GraphQL code generator plug-in that automatically generates utility functions for SWR.", 5 | "main": "build/main/index.js", 6 | "typings": "build/main/index.d.ts", 7 | "module": "build/module/index.js", 8 | "repository": "https://github.com/croutonn/graphql-codegen-plugin-typescript-swr", 9 | "license": "MIT", 10 | "engines": { 11 | "node": ">=16.0.0" 12 | }, 13 | "keywords": [ 14 | "graphql", 15 | "codegen", 16 | "typescript", 17 | "ts", 18 | "swr", 19 | "stale-while-revalidate", 20 | "react" 21 | ], 22 | "scripts": { 23 | "build": "run-p build:*", 24 | "build:main": "tsc -p tsconfig.main.json", 25 | "build:module": "tsc -p tsconfig.module.json", 26 | "fix": "run-s fix:*", 27 | "fix:prettier": "prettier \"src/**/*.ts\" --write", 28 | "fix:lint": "eslint src --ext .ts --fix", 29 | "test": "run-s build test:*", 30 | "test:lint": "eslint src --ext .ts", 31 | "test:prettier": "prettier \"src/**/*.ts\" --list-different", 32 | "test:integrate": "jest --no-watchman", 33 | "watch:build": "tsc -p tsconfig.json -w" 34 | }, 35 | "peerDependencies": { 36 | "graphql": "<17.0.0" 37 | }, 38 | "dependencies": { 39 | "@graphql-codegen/plugin-helpers": "^2.3.1", 40 | "@graphql-codegen/visitor-plugin-common": "^2.5.1", 41 | "@types/micromatch": "^4.0.1", 42 | "graphql-request": "^4.0.0", 43 | "micromatch": "^4.0.4", 44 | "pascal-case": "^3.1.2", 45 | "swr": "^1.0.0", 46 | "tslib": "^2.2.0" 47 | }, 48 | "devDependencies": { 49 | "@graphql-codegen/testing": "^1.17.7", 50 | "@graphql-codegen/typescript": "^2.0.0", 51 | "@graphql-codegen/typescript-graphql-request": "^4.0.0", 52 | "@graphql-codegen/typescript-operations": "^2.0.0", 53 | "@types/jest": "^29.0.0", 54 | "@types/node": "^18.0.0", 55 | "@typescript-eslint/eslint-plugin": "^5.13.0", 56 | "@typescript-eslint/parser": "^5.4.0", 57 | "eslint": "^8.0.0", 58 | "eslint-config-airbnb": "^19.0.0", 59 | "eslint-config-airbnb-typescript": "^17.0.0", 60 | "eslint-config-prettier": "^8.3.0", 61 | "eslint-import-resolver-typescript": "^3.0.0", 62 | "eslint-plugin-import": "^2.23.3", 63 | "eslint-plugin-jsx-a11y": "^6.4.1", 64 | "eslint-plugin-react": "^7.23.2", 65 | "eslint-plugin-react-hooks": "^4.2.0", 66 | "graphql": "<17.0.0", 67 | "jest": "^29.0.0", 68 | "jest-docblock": "^29.0.0", 69 | "jest-junit": "^15.0.0", 70 | "npm-run-all": "^4.1.5", 71 | "prettier": "^2.2.1", 72 | "react": "^17.0.2", 73 | "ts-jest": "^29.0.0", 74 | "typescript": "^4.1.3" 75 | }, 76 | "files": [ 77 | "build/main", 78 | "build/module", 79 | "!**/*.spec.*", 80 | "!**/*.json", 81 | "LICENSE", 82 | "README.md" 83 | ] 84 | } 85 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | } 3 | -------------------------------------------------------------------------------- /src/config.ts: -------------------------------------------------------------------------------- 1 | import { RawClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-common' 2 | 3 | /** 4 | * @description This plugin generates [`graphql-request`](https://www.npmjs.com/package/graphql-request) ready-to-use SDK, which is fully-typed. 5 | */ 6 | 7 | export interface RawSWRPluginConfig extends RawClientSideBasePluginConfig { 8 | /** 9 | * @description By default the `request` method return the `data` or `errors` key from the response. If you need to access the `extensions` key you can use the `rawRequest` method. 10 | * @default false 11 | * 12 | * @exampleMarkdown 13 | * ```yml 14 | * generates: 15 | * path/to/file.ts: 16 | * plugins: 17 | * - typescript 18 | * - typescript-operations 19 | * - typescript-graphql-request 20 | * - graphql-codegen-plugin-typescript-swr 21 | * config: 22 | * rawRequest: true 23 | * ``` 24 | */ 25 | rawRequest?: boolean 26 | excludeQueries?: string | string[] 27 | useSWRInfinite?: string | string[] 28 | autogenSWRKey?: boolean 29 | } 30 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { extname } from 'path' 2 | 3 | import { 4 | Types, 5 | PluginValidateFn, 6 | PluginFunction, 7 | oldVisit, 8 | } from '@graphql-codegen/plugin-helpers' 9 | import { LoadedFragment } from '@graphql-codegen/visitor-plugin-common' 10 | import { GraphQLSchema, concatAST, Kind, FragmentDefinitionNode } from 'graphql' 11 | 12 | import { RawSWRPluginConfig } from './config' 13 | import { SWRVisitor } from './visitor' 14 | 15 | export const plugin: PluginFunction = ( 16 | schema: GraphQLSchema, 17 | documents: Types.DocumentFile[], 18 | config: RawSWRPluginConfig 19 | ) => { 20 | const allAst = concatAST(documents.map((v) => v.document)) 21 | 22 | const allFragments: LoadedFragment[] = [ 23 | // prettier-ignore 24 | ...(allAst.definitions.filter( 25 | (d) => d.kind === Kind.FRAGMENT_DEFINITION 26 | ) as FragmentDefinitionNode[]).map((fragmentDef) => ({ 27 | node: fragmentDef, 28 | name: fragmentDef.name.value, 29 | onType: fragmentDef.typeCondition.name.value, 30 | isExternal: false, 31 | })), 32 | ...(config.externalFragments || []), 33 | ] 34 | 35 | const visitor = new SWRVisitor(schema, allFragments, config) 36 | oldVisit(allAst, { leave: visitor }) 37 | return { 38 | prepend: visitor.getImports(), 39 | content: visitor.sdkContent, 40 | } 41 | } 42 | 43 | export const validate: PluginValidateFn = async ( 44 | _schema: GraphQLSchema, 45 | _documents: Types.DocumentFile[], 46 | _config: RawSWRPluginConfig, 47 | outputFile: string 48 | ) => { 49 | if (extname(outputFile) !== '.ts') { 50 | throw new Error(`Plugin "typescript-swr" requires extension to be ".ts"!`) 51 | } 52 | } 53 | 54 | export { SWRVisitor } 55 | -------------------------------------------------------------------------------- /src/visitor.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ClientSideBasePluginConfig, 3 | ClientSideBaseVisitor, 4 | indentMultiline, 5 | LoadedFragment, 6 | ParsedConfig, 7 | } from '@graphql-codegen/visitor-plugin-common' 8 | import { GraphQLSchema, Kind, OperationDefinitionNode } from 'graphql' 9 | import glob from 'micromatch' 10 | import { pascalCase } from 'pascal-case' 11 | 12 | import { RawSWRPluginConfig } from './config' 13 | 14 | export interface SWRPluginConfig extends ClientSideBasePluginConfig { 15 | rawRequest: boolean 16 | excludeQueries: string | string[] 17 | useSWRInfinite: string | string[] 18 | autogenSWRKey: boolean 19 | } 20 | 21 | export interface Operation { 22 | node: OperationDefinitionNode 23 | documentVariableName: string 24 | operationType: string 25 | operationResultType: string 26 | operationVariablesTypes: string 27 | } 28 | 29 | export interface ComposeQueryHandlerConfig { 30 | autogenKey: SWRPluginConfig['autogenSWRKey'] 31 | infinite: boolean 32 | rawRequest: SWRPluginConfig['rawRequest'] 33 | typesPrefix: ParsedConfig['typesPrefix'] 34 | typesSuffix: ParsedConfig['typesSuffix'] 35 | } 36 | 37 | const composeQueryHandler = ( 38 | operation: Operation, 39 | config: ComposeQueryHandlerConfig 40 | ): string[] => { 41 | const codes: string[] = [] 42 | const { node } = operation 43 | const optionalVariables = 44 | !node.variableDefinitions || 45 | node.variableDefinitions.length === 0 || 46 | node.variableDefinitions.every( 47 | (v) => v.type.kind !== Kind.NON_NULL_TYPE || v.defaultValue 48 | ) 49 | ? '?' 50 | : '' 51 | const name = node.name.value 52 | const pascalName = pascalCase(node.name.value) 53 | const responseType = config.rawRequest 54 | ? `SWRRawResponse<${operation.operationResultType}>` 55 | : operation.operationResultType 56 | const variablesType = operation.operationVariablesTypes 57 | 58 | codes.push(`use${pascalName}(${ 59 | config.autogenKey ? '' : 'key: SWRKeyInterface, ' 60 | }variables${optionalVariables}: ${variablesType}, config?: SWRConfigInterface<${responseType}, ClientError>) { 61 | return useSWR<${responseType}, ClientError>(${ 62 | config.autogenKey 63 | ? `genKey<${variablesType}>('${pascalName}', variables)` 64 | : 'key' 65 | }, () => sdk.${name}(variables), config); 66 | }`) 67 | 68 | if (config.infinite) { 69 | codes.push(`use${pascalName}Infinite(${ 70 | config.autogenKey ? '' : 'id: string, ' 71 | }getKey: ${config.typesPrefix}SWRInfiniteKeyLoader${ 72 | config.typesSuffix 73 | }<${responseType}, ${variablesType}>, variables${optionalVariables}: ${variablesType}, config?: SWRInfiniteConfiguration<${responseType}, ClientError>) { 74 | return useSWRInfinite<${responseType}, ClientError>( 75 | utilsForInfinite.generateGetKey<${responseType}, ${variablesType}>(${ 76 | config.autogenKey 77 | ? `genKey<${variablesType}>('${pascalName}', variables)` 78 | : 'id' 79 | }, getKey), 80 | utilsForInfinite.generateFetcher<${responseType}, ${variablesType}>(sdk.${name}, variables), 81 | config); 82 | }`) 83 | } 84 | 85 | return codes 86 | } 87 | 88 | export class SWRVisitor extends ClientSideBaseVisitor< 89 | RawSWRPluginConfig, 90 | SWRPluginConfig 91 | > { 92 | private _operationsToInclude: Operation[] = [] 93 | 94 | private _enabledInfinite = false 95 | 96 | constructor( 97 | schema: GraphQLSchema, 98 | fragments: LoadedFragment[], 99 | rawConfig: RawSWRPluginConfig 100 | ) { 101 | super(schema, fragments, rawConfig, { 102 | excludeQueries: rawConfig.excludeQueries || null, 103 | useSWRInfinite: rawConfig.useSWRInfinite || null, 104 | autogenSWRKey: rawConfig.autogenSWRKey || false, 105 | }) 106 | 107 | this._enabledInfinite = 108 | (this.config.useSWRInfinite && 109 | typeof this.config.useSWRInfinite === 'string') || 110 | (Array.isArray(this.config.useSWRInfinite) && 111 | this.config.useSWRInfinite.length > 0) 112 | 113 | const typeImport = this.config.useTypeImports ? 'import type' : 'import' 114 | 115 | this._additionalImports.push( 116 | `${typeImport} { ClientError } from 'graphql-request/dist/types';` 117 | ) 118 | 119 | if (this.config.useTypeImports) { 120 | if (this._enabledInfinite) { 121 | this._additionalImports.push( 122 | `import type { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';` 123 | ) 124 | this._additionalImports.push( 125 | `import type { SWRInfiniteConfiguration } from 'swr/infinite';` 126 | ) 127 | this._additionalImports.push(`import useSWR from 'swr';`) 128 | this._additionalImports.push( 129 | `import useSWRInfinite from 'swr/infinite';` 130 | ) 131 | } else { 132 | this._additionalImports.push( 133 | `import type { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';` 134 | ) 135 | this._additionalImports.push(`import useSWR from 'swr';`) 136 | } 137 | } else if (this._enabledInfinite) { 138 | this._additionalImports.push( 139 | `import useSWR, { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';` 140 | ) 141 | this._additionalImports.push( 142 | `import useSWRInfinite, { SWRInfiniteConfiguration } from 'swr/infinite';` 143 | ) 144 | } else { 145 | this._additionalImports.push( 146 | `import useSWR, { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';` 147 | ) 148 | } 149 | } 150 | 151 | protected buildOperation( 152 | node: OperationDefinitionNode, 153 | documentVariableName: string, 154 | operationType: string, 155 | operationResultType: string, 156 | operationVariablesTypes: string 157 | ): string { 158 | this._operationsToInclude.push({ 159 | node, 160 | documentVariableName, 161 | operationType, 162 | operationResultType, 163 | operationVariablesTypes, 164 | }) 165 | 166 | return null 167 | } 168 | 169 | public get sdkContent(): string { 170 | const codes: string[] = [] 171 | const { config } = this 172 | const disabledexcludeQueries = 173 | !config.excludeQueries || 174 | (Array.isArray(config.excludeQueries) && !config.excludeQueries.length) 175 | const allPossibleActions = this._operationsToInclude 176 | .filter((o) => { 177 | if (o.operationType !== 'Query') { 178 | return false 179 | } 180 | if (disabledexcludeQueries) { 181 | return true 182 | } 183 | return !glob.isMatch(o.node.name.value, config.excludeQueries) 184 | }) 185 | .map((o) => 186 | composeQueryHandler(o, { 187 | autogenKey: config.autogenSWRKey, 188 | infinite: 189 | this._enabledInfinite && 190 | glob.isMatch(o.node.name.value, config.useSWRInfinite), 191 | rawRequest: config.rawRequest, 192 | typesPrefix: config.typesPrefix, 193 | typesSuffix: config.typesSuffix, 194 | }) 195 | ) 196 | .reduce((p, c) => p.concat(c), []) 197 | .map((s) => indentMultiline(s, 2)) 198 | 199 | // Add type of SWRRawResponse 200 | if (config.rawRequest) { 201 | codes.push( 202 | `type SWRRawResponse = { data?: Data | undefined; extensions?: any; headers: Headers; status: number; errors?: GraphQLError[] | undefined; };` 203 | ) 204 | } 205 | 206 | // Add type of SWRInfiniteKeyLoader 207 | if (this._enabledInfinite) { 208 | codes.push(`export type ${config.typesPrefix}SWRInfiniteKeyLoader${config.typesSuffix} = ( 209 | index: number, 210 | previousPageData: Data | null 211 | ) => [keyof Variables, Variables[keyof Variables] | null] | null;`) 212 | } 213 | 214 | // Add getSdkWithHooks function 215 | codes.push(`export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) { 216 | const sdk = getSdk(client, withWrapper);`) 217 | 218 | // Add the utility for useSWRInfinite 219 | if (this._enabledInfinite) { 220 | codes.push(` const utilsForInfinite = { 221 | generateGetKey: ( 222 | id: ${config.autogenSWRKey ? 'SWRKeyInterface' : 'string'}, 223 | getKey: ${config.typesPrefix}SWRInfiniteKeyLoader${ 224 | config.typesSuffix 225 | } 226 | ) => (pageIndex: number, previousData: Data | null) => { 227 | const key = getKey(pageIndex, previousData) 228 | return key ? [id, ...key] : null 229 | }, 230 | generateFetcher: (query: (variables: Variables) => Promise, variables?: Variables) => ( 231 | id: string, 232 | fieldName: keyof Variables, 233 | fieldValue: Variables[typeof fieldName] 234 | ) => query({ ...variables, [fieldName]: fieldValue } as Variables) 235 | }`) 236 | } 237 | 238 | // Add the function for auto-generation key for SWR 239 | if (config.autogenSWRKey) { 240 | codes.push( 241 | ` const genKey = = Record>(name: string, object: V = {} as V): SWRKeyInterface => [name, ...Object.keys(object).sort().map(key => object[key])];` 242 | ) 243 | } 244 | 245 | // Add return statement for getSdkWithHooks function and close the function 246 | codes.push(` return { 247 | ...sdk, 248 | ${allPossibleActions.join(',\n')} 249 | }; 250 | }`) 251 | 252 | // Add type of Sdk 253 | codes.push( 254 | `export type ${config.typesPrefix}SdkWithHooks${config.typesSuffix} = ReturnType;` 255 | ) 256 | 257 | return codes.join('\n') 258 | } 259 | } 260 | -------------------------------------------------------------------------------- /tests/outputs/autogenSWRKey.ts: -------------------------------------------------------------------------------- 1 | export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) { 2 | const sdk = getSdk(client, withWrapper); 3 | const utilsForInfinite = { 4 | generateGetKey: ( 5 | id: SWRKeyInterface, 6 | getKey: SWRInfiniteKeyLoader 7 | ) => (pageIndex: number, previousData: Data | null) => { 8 | const key = getKey(pageIndex, previousData) 9 | return key ? [id, ...key] : null 10 | }, 11 | generateFetcher: (query: (variables: Variables) => Promise, variables?: Variables) => ( 12 | id: string, 13 | fieldName: keyof Variables, 14 | fieldValue: Variables[typeof fieldName] 15 | ) => query({ ...variables, [fieldName]: fieldValue } as Variables) 16 | } 17 | const genKey = = Record>(name: string, object: V = {} as V): SWRKeyInterface => [name, ...Object.keys(object).sort().map(key => object[key])]; 18 | return { 19 | ...sdk, 20 | useFeed(variables?: FeedQueryVariables, config?: SWRConfigInterface) { 21 | return useSWR(genKey('Feed', variables), () => sdk.feed(variables), config); 22 | }, 23 | useFeed2(variables: Feed2QueryVariables, config?: SWRConfigInterface) { 24 | return useSWR(genKey('Feed2', variables), () => sdk.feed2(variables), config); 25 | }, 26 | useFeed2Infinite(getKey: SWRInfiniteKeyLoader, variables: Feed2QueryVariables, config?: SWRInfiniteConfiguration) { 27 | return useSWRInfinite( 28 | utilsForInfinite.generateGetKey(genKey('Feed2', variables), getKey), 29 | utilsForInfinite.generateFetcher(sdk.feed2, variables), 30 | config); 31 | }, 32 | useFeed3(variables?: Feed3QueryVariables, config?: SWRConfigInterface) { 33 | return useSWR(genKey('Feed3', variables), () => sdk.feed3(variables), config); 34 | }, 35 | useFeed4(variables?: Feed4QueryVariables, config?: SWRConfigInterface) { 36 | return useSWR(genKey('Feed4', variables), () => sdk.feed4(variables), config); 37 | }, 38 | useFeed4Infinite(getKey: SWRInfiniteKeyLoader, variables?: Feed4QueryVariables, config?: SWRInfiniteConfiguration) { 39 | return useSWRInfinite( 40 | utilsForInfinite.generateGetKey(genKey('Feed4', variables), getKey), 41 | utilsForInfinite.generateFetcher(sdk.feed4, variables), 42 | config); 43 | } 44 | }; 45 | } 46 | export type SdkWithHooks = ReturnType; 47 | -------------------------------------------------------------------------------- /tests/outputs/excludeQueries.ts: -------------------------------------------------------------------------------- 1 | export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) { 2 | const sdk = getSdk(client, withWrapper); 3 | return { 4 | ...sdk, 5 | useFeed(key: SWRKeyInterface, variables?: FeedQueryVariables, config?: SWRConfigInterface) { 6 | return useSWR(key, () => sdk.feed(variables), config); 7 | }, 8 | useFeed4(key: SWRKeyInterface, variables?: Feed4QueryVariables, config?: SWRConfigInterface) { 9 | return useSWR(key, () => sdk.feed4(variables), config); 10 | } 11 | }; 12 | } 13 | export type SdkWithHooks = ReturnType; 14 | -------------------------------------------------------------------------------- /tests/outputs/infinite.ts: -------------------------------------------------------------------------------- 1 | export type SWRInfiniteKeyLoader = ( 2 | index: number, 3 | previousPageData: Data | null 4 | ) => [keyof Variables, Variables[keyof Variables] | null] | null; 5 | export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) { 6 | const sdk = getSdk(client, withWrapper); 7 | const utilsForInfinite = { 8 | generateGetKey: ( 9 | id: string, 10 | getKey: SWRInfiniteKeyLoader 11 | ) => (pageIndex: number, previousData: Data | null) => { 12 | const key = getKey(pageIndex, previousData) 13 | return key ? [id, ...key] : null 14 | }, 15 | generateFetcher: (query: (variables: Variables) => Promise, variables?: Variables) => ( 16 | id: string, 17 | fieldName: keyof Variables, 18 | fieldValue: Variables[typeof fieldName] 19 | ) => query({ ...variables, [fieldName]: fieldValue } as Variables) 20 | } 21 | return { 22 | ...sdk, 23 | useFeed(key: SWRKeyInterface, variables?: FeedQueryVariables, config?: SWRConfigInterface) { 24 | return useSWR(key, () => sdk.feed(variables), config); 25 | }, 26 | useFeed2(key: SWRKeyInterface, variables: Feed2QueryVariables, config?: SWRConfigInterface) { 27 | return useSWR(key, () => sdk.feed2(variables), config); 28 | }, 29 | useFeed2Infinite(id: string, getKey: SWRInfiniteKeyLoader, variables: Feed2QueryVariables, config?: SWRInfiniteConfiguration) { 30 | return useSWRInfinite( 31 | utilsForInfinite.generateGetKey(id, getKey), 32 | utilsForInfinite.generateFetcher(sdk.feed2, variables), 33 | config); 34 | }, 35 | useFeed3(key: SWRKeyInterface, variables?: Feed3QueryVariables, config?: SWRConfigInterface) { 36 | return useSWR(key, () => sdk.feed3(variables), config); 37 | }, 38 | useFeed4(key: SWRKeyInterface, variables?: Feed4QueryVariables, config?: SWRConfigInterface) { 39 | return useSWR(key, () => sdk.feed4(variables), config); 40 | }, 41 | useFeed4Infinite(id: string, getKey: SWRInfiniteKeyLoader, variables?: Feed4QueryVariables, config?: SWRInfiniteConfiguration) { 42 | return useSWRInfinite( 43 | utilsForInfinite.generateGetKey(id, getKey), 44 | utilsForInfinite.generateFetcher(sdk.feed4, variables), 45 | config); 46 | } 47 | }; 48 | } 49 | export type SdkWithHooks = ReturnType; 50 | -------------------------------------------------------------------------------- /tests/outputs/mutations.ts: -------------------------------------------------------------------------------- 1 | export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) { 2 | const sdk = getSdk(client, withWrapper); 3 | return { 4 | ...sdk, 5 | useFeed(key: SWRKeyInterface, variables?: FeedQueryVariables, config?: SWRConfigInterface) { 6 | return useSWR(key, () => sdk.feed(variables), config); 7 | }, 8 | useFeed2(key: SWRKeyInterface, variables: Feed2QueryVariables, config?: SWRConfigInterface) { 9 | return useSWR(key, () => sdk.feed2(variables), config); 10 | }, 11 | useFeed3(key: SWRKeyInterface, variables?: Feed3QueryVariables, config?: SWRConfigInterface) { 12 | return useSWR(key, () => sdk.feed3(variables), config); 13 | }, 14 | useFeed4(key: SWRKeyInterface, variables?: Feed4QueryVariables, config?: SWRConfigInterface) { 15 | return useSWR(key, () => sdk.feed4(variables), config); 16 | } 17 | }; 18 | } 19 | export type SdkWithHooks = ReturnType; 20 | -------------------------------------------------------------------------------- /tests/outputs/rawRequest.ts: -------------------------------------------------------------------------------- 1 | export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) { 2 | const sdk = getSdk(client, withWrapper); 3 | return { 4 | ...sdk, 5 | useFeed(key: SWRKeyInterface, variables?: FeedQueryVariables, config?: SWRConfigInterface) { 6 | return useSWR(key, () => sdk.feed(variables), config); 7 | }, 8 | useFeed2(key: SWRKeyInterface, variables: Feed2QueryVariables, config?: SWRConfigInterface) { 9 | return useSWR(key, () => sdk.feed2(variables), config); 10 | }, 11 | useFeed3(key: SWRKeyInterface, variables?: Feed3QueryVariables, config?: SWRConfigInterface) { 12 | return useSWR(key, () => sdk.feed3(variables), config); 13 | }, 14 | useFeed4(key: SWRKeyInterface, variables?: Feed4QueryVariables, config?: SWRConfigInterface) { 15 | return useSWR(key, () => sdk.feed4(variables), config); 16 | } 17 | }; 18 | } 19 | export type SdkWithHooks = ReturnType; 20 | -------------------------------------------------------------------------------- /tests/outputs/straight.ts: -------------------------------------------------------------------------------- 1 | export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) { 2 | const sdk = getSdk(client, withWrapper); 3 | return { 4 | ...sdk, 5 | useFeed(key: SWRKeyInterface, variables?: FeedQueryVariables, config?: SWRConfigInterface) { 6 | return useSWR(key, () => sdk.feed(variables), config); 7 | }, 8 | useFeed2(key: SWRKeyInterface, variables: Feed2QueryVariables, config?: SWRConfigInterface) { 9 | return useSWR(key, () => sdk.feed2(variables), config); 10 | }, 11 | useFeed3(key: SWRKeyInterface, variables?: Feed3QueryVariables, config?: SWRConfigInterface) { 12 | return useSWR(key, () => sdk.feed3(variables), config); 13 | }, 14 | useFeed4(key: SWRKeyInterface, variables?: Feed4QueryVariables, config?: SWRConfigInterface) { 15 | return useSWR(key, () => sdk.feed4(variables), config); 16 | } 17 | }; 18 | } 19 | export type SdkWithHooks = ReturnType; 20 | -------------------------------------------------------------------------------- /tests/swr.spec.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs' 2 | import { resolve } from 'path' 3 | 4 | import { Types, mergeOutputs } from '@graphql-codegen/plugin-helpers' 5 | import { validateTs } from '@graphql-codegen/testing' 6 | import { 7 | plugin as tsPlugin, 8 | TypeScriptPluginConfig, 9 | } from '@graphql-codegen/typescript' 10 | import { plugin as graphQLRequestPlugin } from '@graphql-codegen/typescript-graphql-request' 11 | import { GraphQLRequestPluginConfig } from '@graphql-codegen/typescript-graphql-request/visitor' 12 | import { 13 | plugin as tsDocumentsPlugin, 14 | TypeScriptDocumentsPluginConfig, 15 | } from '@graphql-codegen/typescript-operations' 16 | import { parse, GraphQLSchema, buildClientSchema } from 'graphql' 17 | 18 | import { RawSWRPluginConfig } from '../src/config' 19 | import { plugin } from '../src/index' 20 | 21 | type PluginsConfig = Partial< 22 | TypeScriptPluginConfig & 23 | TypeScriptDocumentsPluginConfig & 24 | GraphQLRequestPluginConfig & 25 | RawSWRPluginConfig 26 | > 27 | 28 | const readOutput = (name: string): string => 29 | fs.readFileSync(resolve(__dirname, `./outputs/${name}.ts`), 'utf-8') 30 | 31 | describe('SWR', () => { 32 | const schema = buildClientSchema(require('../dev-test/githunt/schema.json')) 33 | 34 | const basicDoc = parse(/* GraphQL */ ` 35 | query feed { 36 | feed { 37 | id 38 | commentCount 39 | repository { 40 | owner { 41 | avatar_url 42 | } 43 | } 44 | } 45 | } 46 | query feed2($v: String!) { 47 | feed { 48 | id 49 | } 50 | } 51 | query feed3($v: String) { 52 | feed { 53 | id 54 | } 55 | } 56 | query feed4($v: String! = "TEST") { 57 | feed { 58 | id 59 | } 60 | } 61 | `) 62 | 63 | const basicUsage = ` 64 | async function test() { 65 | const client = new GraphQLClient(''); 66 | const sdk = getSdkWithHooks(client); 67 | 68 | await sdk.feed(); 69 | await sdk.feed3(); 70 | await sdk.feed4(); 71 | const result = await sdk.feed2({ v: "1" }); 72 | if (result.feed) { 73 | if (result.feed[0]) { 74 | const id = result.feed[0].id 75 | } 76 | } 77 | }` 78 | 79 | const validate = async ( 80 | content: Types.PluginOutput, 81 | config: PluginsConfig, 82 | docs: Types.DocumentFile[], 83 | pluginSchema: GraphQLSchema, 84 | usage: string 85 | ) => { 86 | const m = mergeOutputs([ 87 | await tsPlugin(pluginSchema, docs, config, { outputFile: '' }), 88 | await tsDocumentsPlugin(pluginSchema, docs, config), 89 | await graphQLRequestPlugin(pluginSchema, docs, config), 90 | content, 91 | usage, 92 | ]) 93 | 94 | await validateTs(m) 95 | 96 | return m 97 | } 98 | 99 | describe('sdk', () => { 100 | it('Should generate import declarations of output correctly', async () => { 101 | const config: PluginsConfig = {} 102 | const docs = [{ location: '', document: basicDoc }] 103 | const usage = `` 104 | 105 | const content = (await plugin(schema, docs, config, { 106 | outputFile: 'graphql.ts', 107 | })) as Types.ComplexPluginOutput 108 | 109 | expect(content.prepend).toContain( 110 | `import useSWR, { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';` 111 | ) 112 | 113 | await validate(content, config, docs, schema, usage) 114 | }) 115 | 116 | it('Should support useTypeImports', async () => { 117 | const config: PluginsConfig = { useTypeImports: true } 118 | const docs = [{ location: '', document: basicDoc }] 119 | const usage = `` 120 | 121 | const content = (await plugin(schema, docs, config, { 122 | outputFile: 'graphql.ts', 123 | })) as Types.ComplexPluginOutput 124 | 125 | expect(content.prepend).toContain(`import useSWR from 'swr';`) 126 | expect(content.prepend).toContain( 127 | `import type { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';` 128 | ) 129 | 130 | await validate(content, config, docs, schema, usage) 131 | }) 132 | }) 133 | 134 | describe('plugin-typescript-swr', () => { 135 | it('Should generate Hooks API of output correctly', async () => { 136 | const config: PluginsConfig = {} 137 | const docs = [{ location: '', document: basicDoc }] 138 | 139 | const content = (await plugin(schema, docs, config, { 140 | outputFile: 'graphql.ts', 141 | })) as Types.ComplexPluginOutput 142 | 143 | const usage = basicUsage 144 | const output = await validate(content, config, docs, schema, usage) 145 | expect(output).toContain(readOutput('straight')) 146 | }) 147 | 148 | it('Should generate the output from which mutation operation has been removed', async () => { 149 | const config: PluginsConfig = {} 150 | const document = parse(/* GraphQL */ ` 151 | query feed { 152 | feed { 153 | id 154 | commentCount 155 | repository { 156 | owner { 157 | avatar_url 158 | } 159 | } 160 | } 161 | } 162 | query feed2($v: String!) { 163 | feed { 164 | id 165 | } 166 | } 167 | query feed3($v: String) { 168 | feed { 169 | id 170 | } 171 | } 172 | query feed4($v: String! = "TEST") { 173 | feed { 174 | id 175 | } 176 | } 177 | mutation submitComment( 178 | $repoFullName: String! 179 | $commentContent: String! 180 | ) { 181 | submitComment( 182 | repoFullName: $repoFullName 183 | commentContent: $commentContent 184 | ) { 185 | ...CommentsPageComment 186 | } 187 | } 188 | fragment CommentsPageComment on Comment { 189 | id 190 | postedBy { 191 | login 192 | html_url 193 | } 194 | createdAt 195 | content 196 | } 197 | `) 198 | const docs = [{ location: '', document }] 199 | 200 | const content = (await plugin(schema, docs, config, { 201 | outputFile: 'graphql.ts', 202 | })) as Types.ComplexPluginOutput 203 | 204 | const usage = basicUsage 205 | const output = await validate(content, config, docs, schema, usage) 206 | expect(output).toContain(readOutput('mutations')) 207 | }) 208 | 209 | it('Should work `excludeQueries` option correctly', async () => { 210 | const config: PluginsConfig = { 211 | excludeQueries: ['feed[2-3]', 'hoge', 'foo'], 212 | } 213 | const docs = [{ location: '', document: basicDoc }] 214 | 215 | const content = (await plugin(schema, docs, config, { 216 | outputFile: 'graphql.ts', 217 | })) as Types.ComplexPluginOutput 218 | 219 | const usage = basicUsage 220 | const output = await validate(content, config, docs, schema, usage) 221 | expect(output).toContain(readOutput('excludeQueries')) 222 | }) 223 | 224 | it('Should work `useSWRInfinite` option correctly', async () => { 225 | const config: PluginsConfig = { 226 | useSWRInfinite: ['feed[24]'], 227 | } 228 | const docs = [{ location: '', document: basicDoc }] 229 | 230 | const content = (await plugin(schema, docs, config, { 231 | outputFile: 'graphql.ts', 232 | })) as Types.ComplexPluginOutput 233 | 234 | const usage = basicUsage 235 | const output = await validate(content, config, docs, schema, usage) 236 | expect(content.prepend).toContain( 237 | `import useSWR, { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';` 238 | ) 239 | expect(content.prepend).toContain( 240 | `import useSWRInfinite, { SWRInfiniteConfiguration } from 'swr/infinite';` 241 | ) 242 | expect(output).toContain(readOutput('infinite')) 243 | }) 244 | }) 245 | 246 | it('Should work `autogenSWRKey` option correctly', async () => { 247 | const config: PluginsConfig = { 248 | autogenSWRKey: true, 249 | useSWRInfinite: ['feed[24]'], 250 | } 251 | const docs = [{ location: '', document: basicDoc }] 252 | 253 | const content = (await plugin(schema, docs, config, { 254 | outputFile: 'graphql.ts', 255 | })) as Types.ComplexPluginOutput 256 | 257 | const usage = basicUsage 258 | const output = await validate(content, config, docs, schema, usage) 259 | expect(output).toContain(readOutput('autogenSWRKey')) 260 | }) 261 | 262 | it('Should work `rawRequest` option correctly', async () => { 263 | const config: PluginsConfig = { 264 | rawRequest: true, 265 | } 266 | const docs = [{ location: '', document: basicDoc }] 267 | 268 | const content = (await plugin(schema, docs, config, { 269 | outputFile: 'graphql.ts', 270 | })) as Types.ComplexPluginOutput 271 | 272 | const usage = basicUsage 273 | const output = await validate(content, config, docs, schema, usage) 274 | expect(output).toContain( 275 | "import { ClientError } from 'graphql-request/dist/types'" 276 | ) 277 | expect(output).toContain(readOutput('rawRequest')) 278 | }) 279 | 280 | it('Should work `typesPrefix` and `typesSuffix` option correctly', async () => { 281 | const typesPrefix = 'P' 282 | const typesSuffix = 'S' 283 | const config: PluginsConfig = { 284 | typesPrefix, 285 | typesSuffix, 286 | useSWRInfinite: ['feed'], 287 | } 288 | const docs = [{ location: '', document: basicDoc }] 289 | 290 | const content = (await plugin(schema, docs, config, { 291 | outputFile: 'graphql.ts', 292 | })) as Types.ComplexPluginOutput 293 | 294 | const usage = basicUsage 295 | const output = await validate(content, config, docs, schema, usage) 296 | expect(output).toContain( 297 | `export type ${typesPrefix}SWRInfiniteKeyLoader${typesSuffix}` 298 | ) 299 | expect(output).toContain( 300 | `getKey: ${typesPrefix}SWRInfiniteKeyLoader${typesSuffix}<${typesPrefix}FeedQuery${typesSuffix}, ${typesPrefix}FeedQueryVariables${typesSuffix}>` 301 | ) 302 | expect(output).toContain( 303 | `export type ${typesPrefix}SdkWithHooks${typesSuffix} =` 304 | ) 305 | }) 306 | }) 307 | -------------------------------------------------------------------------------- /tests/visitor.spec.ts: -------------------------------------------------------------------------------- 1 | import { GraphQLSchema } from 'graphql'; 2 | import { SWRVisitor } from '../src/visitor' 3 | 4 | describe('SWRVisitor', () => { 5 | describe('sdkContent', () => { 6 | it('should export SWRInfiniteKeyLoader', () => { 7 | const schema = new GraphQLSchema({ 8 | }) 9 | const visitor = new SWRVisitor( 10 | schema, 11 | [], 12 | { 13 | useSWRInfinite: ['_query_'] 14 | } 15 | ) 16 | expect(visitor.sdkContent).toContain('export type SWRInfiniteKeyLoader