Last active
          November 24, 2020 05:01 
        
      - 
      
- 
        Save bannzai/3842eabe3423a2662b41787129c32c98 to your computer and use it in GitHub Desktop. 
    graphql_codegen_typescript
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | generates: | |
| types.ts: | |
| plugins: | |
| - typescript | |
| - typescript-operations | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # This example isn't | |
| # using GraphQL operations | |
| query GetUser { | |
| me { | |
| id | |
| } | |
| user(id: "3") { | |
| id | |
| username | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | scalar Date | |
| schema { | |
| query: Query | |
| } | |
| type Query { | |
| me: User! | |
| user(id: ID!): User | |
| allUsers: [User] | |
| search(term: String!): [SearchResult!]! | |
| myChats: [Chat!]! | |
| } | |
| enum Role { | |
| USER, | |
| ADMIN, | |
| } | |
| interface Node { | |
| id: ID! | |
| } | |
| union SearchResult = User | Chat | ChatMessage | |
| type User implements Node { | |
| id: ID! | |
| username: String! | |
| email: String! | |
| role: Role! | |
| } | |
| type Chat implements Node { | |
| id: ID! | |
| users: [User!]! | |
| messages: [ChatMessage!]! | |
| } | |
| type ChatMessage implements Node { | |
| id: ID! | |
| content: String! | |
| time: Date! | |
| user: User! | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | export type Maybe<T> = T | null; | |
| export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }; | |
| export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in keyof Pick<T, K>]?: Maybe<Pick<T, K>[SubKey]> }; | |
| /** All built-in and custom scalars, mapped to their actual values */ | |
| export type Scalars = { | |
| ID: string; | |
| String: string; | |
| Boolean: boolean; | |
| Int: number; | |
| Float: number; | |
| Date: any; | |
| }; | |
| export type Query = { | |
| __typename?: 'Query'; | |
| me: User; | |
| user?: Maybe<User>; | |
| allUsers?: Maybe<Array<Maybe<User>>>; | |
| search: Array<SearchResult>; | |
| myChats: Array<Chat>; | |
| }; | |
| export type QueryUserArgs = { | |
| id: Scalars['ID']; | |
| }; | |
| export type QuerySearchArgs = { | |
| term: Scalars['String']; | |
| }; | |
| export enum Role { | |
| User = 'USER', | |
| Admin = 'ADMIN' | |
| } | |
| export type Node = { | |
| id: Scalars['ID']; | |
| }; | |
| export type SearchResult = User | Chat | ChatMessage; | |
| export type User = Node & { | |
| __typename?: 'User'; | |
| id: Scalars['ID']; | |
| username: Scalars['String']; | |
| email: Scalars['String']; | |
| role: Role; | |
| }; | |
| export type Chat = Node & { | |
| __typename?: 'Chat'; | |
| id: Scalars['ID']; | |
| users: Array<User>; | |
| messages: Array<ChatMessage>; | |
| }; | |
| export type ChatMessage = Node & { | |
| __typename?: 'ChatMessage'; | |
| id: Scalars['ID']; | |
| content: Scalars['String']; | |
| time: Scalars['Date']; | |
| user: User; | |
| }; | |
| export type GetUserQueryVariables = Exact<{ [key: string]: never; }>; | |
| export type GetUserQuery = ( | |
| { __typename?: 'Query' } | |
| & { me: ( | |
| { __typename?: 'User' } | |
| & Pick<User, 'id'> | |
| ), user?: Maybe<( | |
| { __typename?: 'User' } | |
| & Pick<User, 'id' | 'username'> | |
| )> } | |
| ); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | export type Maybe<T> = T | null; | |
| export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }; | |
| export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in keyof Pick<T, K>]?: Maybe<Pick<T, K>[SubKey]> }; | |
| /** All built-in and custom scalars, mapped to their actual values */ | |
| export type Scalars = { | |
| ID: string; | |
| String: string; | |
| Boolean: boolean; | |
| Int: number; | |
| Float: number; | |
| Date: any; | |
| }; | |
| export type Query = { | |
| __typename?: 'Query'; | |
| me: User; | |
| user?: Maybe<User>; | |
| allUsers?: Maybe<Array<Maybe<User>>>; | |
| search: Array<SearchResult>; | |
| myChats: Array<Chat>; | |
| }; | |
| export type QueryUserArgs = { | |
| id: Scalars['ID']; | |
| }; | |
| export type QuerySearchArgs = { | |
| term: Scalars['String']; | |
| }; | |
| export enum Role { | |
| User = 'USER', | |
| Admin = 'ADMIN' | |
| } | |
| export type Node = { | |
| id: Scalars['ID']; | |
| }; | |
| export type SearchResult = User | Chat | ChatMessage; | |
| export type User = Node & { | |
| __typename?: 'User'; | |
| id: Scalars['ID']; | |
| username: Scalars['String']; | |
| email: Scalars['String']; | |
| role: Role; | |
| }; | |
| export type Chat = Node & { | |
| __typename?: 'Chat'; | |
| id: Scalars['ID']; | |
| users: Array<User>; | |
| messages: Array<ChatMessage>; | |
| }; | |
| export type ChatMessage = Node & { | |
| __typename?: 'ChatMessage'; | |
| id: Scalars['ID']; | |
| content: Scalars['String']; | |
| time: Scalars['Date']; | |
| user: User; | |
| }; | |
| export type GetUserQueryVariables = Exact<{ [key: string]: never; }>; | |
| export type GetUserQuery = ( | |
| { __typename?: 'Query' } | |
| & { | |
| me: ( | |
| { __typename?: 'User' } | |
| & Pick<User, 'id'> | |
| ), user?: Maybe<( | |
| { __typename?: 'User' } | |
| & Pick<User, 'id' | 'username'> | |
| )> | |
| } | |
| ); | |
| class FakeImpl implements GetUserQuery { | |
| __typename?: "Query" | undefined; | |
| me!: { __typename?: "User" | undefined; } & Pick<User, "id">; | |
| user?: ({ __typename?: "User" | undefined; } & Pick<User, "id" | "username">) | null | undefined; | |
| } | |
| export function receiveMe(t: Pick<User, 'id'>) { } | |
| export function receiveUser(t: Pick<User, 'id' | 'username'>) { } | |
| export function y() { | |
| const x = new FakeImpl(); | |
| receiveMe(x.me); | |
| receiveMe(x.user!); // これが受け取れるのが問題か | |
| receiveUser(x.user!); | |
| receiveUser(x.me!); // これはコンパイルエラーできるんだけどね | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
ここで試した
https://graphql-code-generator.com/