diff --git a/.changeset/two-dolphins-deliver.md b/.changeset/two-dolphins-deliver.md new file mode 100644 index 00000000000..49dfd820876 --- /dev/null +++ b/.changeset/two-dolphins-deliver.md @@ -0,0 +1,6 @@ +--- +'@graphql-codegen/visitor-plugin-common': patch +'@graphql-codegen/typescript-operations': patch +--- + +Generate $fragmentName for fragment subtypes for fragment masking diff --git a/dev-test/codegen.yml b/dev-test/codegen.yml index 2a8af874994..27dedd67d36 100644 --- a/dev-test/codegen.yml +++ b/dev-test/codegen.yml @@ -417,3 +417,9 @@ generates: preset: gql-tag-operations-preset presetConfig: fragmentMasking: true + ./dev-test/gql-tag-operations-masking-star-wars/gql: + schema: ./dev-test/gql-tag-operations-masking-star-wars/schema.json + documents: './dev-test/gql-tag-operations-masking-star-wars/src/**/*.tsx' + preset: gql-tag-operations-preset + presetConfig: + fragmentMasking: true diff --git a/dev-test/gql-tag-operations-masking-star-wars/gql/fragment-masking.ts b/dev-test/gql-tag-operations-masking-star-wars/gql/fragment-masking.ts new file mode 100644 index 00000000000..be1af11b1fc --- /dev/null +++ b/dev-test/gql-tag-operations-masking-star-wars/gql/fragment-masking.ts @@ -0,0 +1,19 @@ +import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + +export type FragmentType> = TDocumentType extends DocumentNode< + infer TType, + any +> + ? TType extends { ' $fragmentName': infer TKey } + ? TKey extends string + ? { ' $fragmentRefs': { [key in TKey]: TType } } + : never + : never + : never; + +export function useFragment( + _documentNode: DocumentNode, + fragmentType: FragmentType> +): TType { + return fragmentType as any; +} diff --git a/dev-test/gql-tag-operations-masking-star-wars/gql/gql.ts b/dev-test/gql-tag-operations-masking-star-wars/gql/gql.ts new file mode 100644 index 00000000000..3c05e6ccf6d --- /dev/null +++ b/dev-test/gql-tag-operations-masking-star-wars/gql/gql.ts @@ -0,0 +1,29 @@ +/* eslint-disable */ +import * as graphql from './graphql'; +import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + +const documents = { + '\n query HeroDetailsWithFragment($episode: Episode) {\n hero(episode: $episode) {\n ...HeroDetails\n }\n }\n': + graphql.HeroDetailsWithFragmentDocument, + '\n fragment HeroDetails on Character {\n __typename\n name\n ... on Human {\n height\n }\n ... on Droid {\n primaryFunction\n }\n }\n': + graphql.HeroDetailsFragmentDoc, +}; + +export function gql( + source: '\n query HeroDetailsWithFragment($episode: Episode) {\n hero(episode: $episode) {\n ...HeroDetails\n }\n }\n' +): typeof documents['\n query HeroDetailsWithFragment($episode: Episode) {\n hero(episode: $episode) {\n ...HeroDetails\n }\n }\n']; +export function gql( + source: '\n fragment HeroDetails on Character {\n __typename\n name\n ... on Human {\n height\n }\n ... on Droid {\n primaryFunction\n }\n }\n' +): typeof documents['\n fragment HeroDetails on Character {\n __typename\n name\n ... on Human {\n height\n }\n ... on Droid {\n primaryFunction\n }\n }\n']; + +export function gql(source: string): unknown; +export function gql(source: string) { + return (documents as any)[source] ?? {}; +} + +export type DocumentType> = TDocumentNode extends DocumentNode< + infer TType, + any +> + ? TType + : never; diff --git a/dev-test/gql-tag-operations-masking-star-wars/gql/graphql.ts b/dev-test/gql-tag-operations-masking-star-wars/gql/graphql.ts new file mode 100644 index 00000000000..bd97e97cc66 --- /dev/null +++ b/dev-test/gql-tag-operations-masking-star-wars/gql/graphql.ts @@ -0,0 +1,335 @@ +/* eslint-disable */ +import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +export type Maybe = T | null; +export type InputMaybe = Maybe; +export type Exact = { [K in keyof T]: T[K] }; +export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; +export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; +/** All built-in and custom scalars, mapped to their actual values */ +export type Scalars = { + ID: string; + String: string; + Boolean: boolean; + Int: number; + Float: number; +}; + +/** A character from the Star Wars universe */ +export type Character = { + /** The movies this character appears in */ + appearsIn: Array>; + /** The friends of the character, or an empty list if they have none */ + friends?: Maybe>>; + /** The friends of the character exposed as a connection with edges */ + friendsConnection: FriendsConnection; + /** The ID of the character */ + id: Scalars['ID']; + /** The name of the character */ + name: Scalars['String']; +}; + +/** A character from the Star Wars universe */ +export type CharacterFriendsConnectionArgs = { + after?: InputMaybe; + first?: InputMaybe; +}; + +/** The input object sent when passing a color */ +export type ColorInput = { + blue: Scalars['Int']; + green: Scalars['Int']; + red: Scalars['Int']; +}; + +/** An autonomous mechanical character in the Star Wars universe */ +export type Droid = Character & { + __typename?: 'Droid'; + /** The movies this droid appears in */ + appearsIn: Array>; + /** This droid's friends, or an empty list if they have none */ + friends?: Maybe>>; + /** The friends of the droid exposed as a connection with edges */ + friendsConnection: FriendsConnection; + /** The ID of the droid */ + id: Scalars['ID']; + /** What others call this droid */ + name: Scalars['String']; + /** This droid's primary function */ + primaryFunction?: Maybe; +}; + +/** An autonomous mechanical character in the Star Wars universe */ +export type DroidFriendsConnectionArgs = { + after?: InputMaybe; + first?: InputMaybe; +}; + +/** The episodes in the Star Wars trilogy */ +export enum Episode { + /** Star Wars Episode V: The Empire Strikes Back, released in 1980. */ + Empire = 'EMPIRE', + /** Star Wars Episode VI: Return of the Jedi, released in 1983. */ + Jedi = 'JEDI', + /** Star Wars Episode IV: A New Hope, released in 1977. */ + Newhope = 'NEWHOPE', +} + +/** A connection object for a character's friends */ +export type FriendsConnection = { + __typename?: 'FriendsConnection'; + /** The edges for each of the character's friends. */ + edges?: Maybe>>; + /** A list of the friends, as a convenience when edges are not needed. */ + friends?: Maybe>>; + /** Information for paginating this connection */ + pageInfo: PageInfo; + /** The total number of friends */ + totalCount?: Maybe; +}; + +/** An edge object for a character's friends */ +export type FriendsEdge = { + __typename?: 'FriendsEdge'; + /** A cursor used for pagination */ + cursor: Scalars['ID']; + /** The character represented by this friendship edge */ + node?: Maybe; +}; + +/** A humanoid creature from the Star Wars universe */ +export type Human = Character & { + __typename?: 'Human'; + /** The movies this human appears in */ + appearsIn: Array>; + /** This human's friends, or an empty list if they have none */ + friends?: Maybe>>; + /** The friends of the human exposed as a connection with edges */ + friendsConnection: FriendsConnection; + /** Height in the preferred unit, default is meters */ + height?: Maybe; + /** The home planet of the human, or null if unknown */ + homePlanet?: Maybe; + /** The ID of the human */ + id: Scalars['ID']; + /** Mass in kilograms, or null if unknown */ + mass?: Maybe; + /** What this human calls themselves */ + name: Scalars['String']; + /** A list of starships this person has piloted, or an empty list if none */ + starships?: Maybe>>; +}; + +/** A humanoid creature from the Star Wars universe */ +export type HumanFriendsConnectionArgs = { + after?: InputMaybe; + first?: InputMaybe; +}; + +/** A humanoid creature from the Star Wars universe */ +export type HumanHeightArgs = { + unit?: InputMaybe; +}; + +/** Units of height */ +export enum LengthUnit { + /** Primarily used in the United States */ + Foot = 'FOOT', + /** The standard unit around the world */ + Meter = 'METER', +} + +/** The mutation type, represents all updates we can make to our data */ +export type Mutation = { + __typename?: 'Mutation'; + createReview?: Maybe; +}; + +/** The mutation type, represents all updates we can make to our data */ +export type MutationCreateReviewArgs = { + episode?: InputMaybe; + review: ReviewInput; +}; + +/** Information for paginating this connection */ +export type PageInfo = { + __typename?: 'PageInfo'; + endCursor?: Maybe; + hasNextPage: Scalars['Boolean']; + startCursor?: Maybe; +}; + +/** The query type, represents all of the entry points into our object graph */ +export type Query = { + __typename?: 'Query'; + character?: Maybe; + droid?: Maybe; + hero?: Maybe; + human?: Maybe; + reviews?: Maybe>>; + search?: Maybe>>; + starship?: Maybe; +}; + +/** The query type, represents all of the entry points into our object graph */ +export type QueryCharacterArgs = { + id: Scalars['ID']; +}; + +/** The query type, represents all of the entry points into our object graph */ +export type QueryDroidArgs = { + id: Scalars['ID']; +}; + +/** The query type, represents all of the entry points into our object graph */ +export type QueryHeroArgs = { + episode?: InputMaybe; +}; + +/** The query type, represents all of the entry points into our object graph */ +export type QueryHumanArgs = { + id: Scalars['ID']; +}; + +/** The query type, represents all of the entry points into our object graph */ +export type QueryReviewsArgs = { + episode: Episode; +}; + +/** The query type, represents all of the entry points into our object graph */ +export type QuerySearchArgs = { + text?: InputMaybe; +}; + +/** The query type, represents all of the entry points into our object graph */ +export type QueryStarshipArgs = { + id: Scalars['ID']; +}; + +/** Represents a review for a movie */ +export type Review = { + __typename?: 'Review'; + /** Comment about the movie */ + commentary?: Maybe; + /** The number of stars this review gave, 1-5 */ + stars: Scalars['Int']; +}; + +/** The input object sent when someone is creating a new review */ +export type ReviewInput = { + /** Comment about the movie, optional */ + commentary?: InputMaybe; + /** Favorite color, optional */ + favoriteColor?: InputMaybe; + /** 0-5 stars */ + stars: Scalars['Int']; +}; + +export type SearchResult = Droid | Human | Starship; + +export type Starship = { + __typename?: 'Starship'; + /** The ID of the starship */ + id: Scalars['ID']; + /** Length of the starship, along the longest axis */ + length?: Maybe; + /** The name of the starship */ + name: Scalars['String']; +}; + +export type StarshipLengthArgs = { + unit?: InputMaybe; +}; + +export type HeroDetailsWithFragmentQueryVariables = Exact<{ + episode?: InputMaybe; +}>; + +export type HeroDetailsWithFragmentQuery = { + __typename?: 'Query'; + hero?: + | ({ __typename?: 'Droid' } & { ' $fragmentRefs': { HeroDetails_Droid_Fragment: HeroDetails_Droid_Fragment } }) + | ({ __typename?: 'Human' } & { ' $fragmentRefs': { HeroDetails_Human_Fragment: HeroDetails_Human_Fragment } }) + | null; +}; + +type HeroDetails_Droid_Fragment = { __typename: 'Droid'; primaryFunction?: string | null; name: string } & { + ' $fragmentName': 'HeroDetails_Droid_Fragment'; +}; + +type HeroDetails_Human_Fragment = { __typename: 'Human'; height?: number | null; name: string } & { + ' $fragmentName': 'HeroDetails_Human_Fragment'; +}; + +export type HeroDetailsFragment = HeroDetails_Droid_Fragment | HeroDetails_Human_Fragment; + +export const HeroDetailsFragmentDoc = { + kind: 'Document', + definitions: [ + { + kind: 'FragmentDefinition', + name: { kind: 'Name', value: 'HeroDetails' }, + typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Character' } }, + selectionSet: { + kind: 'SelectionSet', + selections: [ + { kind: 'Field', name: { kind: 'Name', value: '__typename' } }, + { kind: 'Field', name: { kind: 'Name', value: 'name' } }, + { + kind: 'InlineFragment', + typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Human' } }, + selectionSet: { + kind: 'SelectionSet', + selections: [{ kind: 'Field', name: { kind: 'Name', value: 'height' } }], + }, + }, + { + kind: 'InlineFragment', + typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Droid' } }, + selectionSet: { + kind: 'SelectionSet', + selections: [{ kind: 'Field', name: { kind: 'Name', value: 'primaryFunction' } }], + }, + }, + ], + }, + }, + ], +} as unknown as DocumentNode; +export const HeroDetailsWithFragmentDocument = { + kind: 'Document', + definitions: [ + { + kind: 'OperationDefinition', + operation: 'query', + name: { kind: 'Name', value: 'HeroDetailsWithFragment' }, + variableDefinitions: [ + { + kind: 'VariableDefinition', + variable: { kind: 'Variable', name: { kind: 'Name', value: 'episode' } }, + type: { kind: 'NamedType', name: { kind: 'Name', value: 'Episode' } }, + }, + ], + selectionSet: { + kind: 'SelectionSet', + selections: [ + { + kind: 'Field', + name: { kind: 'Name', value: 'hero' }, + arguments: [ + { + kind: 'Argument', + name: { kind: 'Name', value: 'episode' }, + value: { kind: 'Variable', name: { kind: 'Name', value: 'episode' } }, + }, + ], + selectionSet: { + kind: 'SelectionSet', + selections: [{ kind: 'FragmentSpread', name: { kind: 'Name', value: 'HeroDetails' } }], + }, + }, + ], + }, + }, + ...HeroDetailsFragmentDoc.definitions, + ], +} as unknown as DocumentNode; diff --git a/dev-test/gql-tag-operations-masking-star-wars/gql/index.ts b/dev-test/gql-tag-operations-masking-star-wars/gql/index.ts new file mode 100644 index 00000000000..e33dcd39912 --- /dev/null +++ b/dev-test/gql-tag-operations-masking-star-wars/gql/index.ts @@ -0,0 +1,2 @@ +export * from './gql'; +export * from './fragment-masking'; diff --git a/dev-test/gql-tag-operations-masking-star-wars/schema.json b/dev-test/gql-tag-operations-masking-star-wars/schema.json new file mode 100644 index 00000000000..79d01ff8340 --- /dev/null +++ b/dev-test/gql-tag-operations-masking-star-wars/schema.json @@ -0,0 +1,2100 @@ +{ + "data": { + "__schema": { + "queryType": { + "name": "Query" + }, + "mutationType": { + "name": "Mutation" + }, + "subscriptionType": null, + "types": [ + { + "kind": "OBJECT", + "name": "Query", + "description": "The query type, represents all of the entry points into our object graph", + "fields": [ + { + "name": "hero", + "description": "", + "args": [ + { + "name": "episode", + "description": "", + "type": { + "kind": "ENUM", + "name": "Episode", + "ofType": null + }, + "defaultValue": null + } + ], + "type": { + "kind": "INTERFACE", + "name": "Character", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "reviews", + "description": "", + "args": [ + { + "name": "episode", + "description": "", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "ENUM", + "name": "Episode", + "ofType": null + } + }, + "defaultValue": null + } + ], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "Review", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "search", + "description": "", + "args": [ + { + "name": "text", + "description": "", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "defaultValue": null + } + ], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "UNION", + "name": "SearchResult", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "character", + "description": "", + "args": [ + { + "name": "id", + "description": "", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + } + }, + "defaultValue": null + } + ], + "type": { + "kind": "INTERFACE", + "name": "Character", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "droid", + "description": "", + "args": [ + { + "name": "id", + "description": "", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + } + }, + "defaultValue": null + } + ], + "type": { + "kind": "OBJECT", + "name": "Droid", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "human", + "description": "", + "args": [ + { + "name": "id", + "description": "", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + } + }, + "defaultValue": null + } + ], + "type": { + "kind": "OBJECT", + "name": "Human", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "starship", + "description": "", + "args": [ + { + "name": "id", + "description": "", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + } + }, + "defaultValue": null + } + ], + "type": { + "kind": "OBJECT", + "name": "Starship", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "ENUM", + "name": "Episode", + "description": "The episodes in the Star Wars trilogy", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": [ + { + "name": "NEWHOPE", + "description": "Star Wars Episode IV: A New Hope, released in 1977.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "EMPIRE", + "description": "Star Wars Episode V: The Empire Strikes Back, released in 1980.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "JEDI", + "description": "Star Wars Episode VI: Return of the Jedi, released in 1983.", + "isDeprecated": false, + "deprecationReason": null + } + ], + "possibleTypes": null + }, + { + "kind": "INTERFACE", + "name": "Character", + "description": "A character from the Star Wars universe", + "fields": [ + { + "name": "id", + "description": "The ID of the character", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "name", + "description": "The name of the character", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "friends", + "description": "The friends of the character, or an empty list if they have none", + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "INTERFACE", + "name": "Character", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "friendsConnection", + "description": "The friends of the character exposed as a connection with edges", + "args": [ + { + "name": "first", + "description": "", + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + }, + "defaultValue": null + }, + { + "name": "after", + "description": "", + "type": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + }, + "defaultValue": null + } + ], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "FriendsConnection", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "appearsIn", + "description": "The movies this character appears in", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "ENUM", + "name": "Episode", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": [ + { + "kind": "OBJECT", + "name": "Human", + "ofType": null + }, + { + "kind": "OBJECT", + "name": "Droid", + "ofType": null + } + ] + }, + { + "kind": "SCALAR", + "name": "ID", + "description": "The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `\"4\"`) or integer (such as `4`) input value will be accepted as an ID.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "String", + "description": "The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "Int", + "description": "The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1. ", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "FriendsConnection", + "description": "A connection object for a character's friends", + "fields": [ + { + "name": "totalCount", + "description": "The total number of friends", + "args": [], + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "edges", + "description": "The edges for each of the character's friends.", + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "FriendsEdge", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "friends", + "description": "A list of the friends, as a convenience when edges are not needed.", + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "INTERFACE", + "name": "Character", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "pageInfo", + "description": "Information for paginating this connection", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "PageInfo", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "FriendsEdge", + "description": "An edge object for a character's friends", + "fields": [ + { + "name": "cursor", + "description": "A cursor used for pagination", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "node", + "description": "The character represented by this friendship edge", + "args": [], + "type": { + "kind": "INTERFACE", + "name": "Character", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "PageInfo", + "description": "Information for paginating this connection", + "fields": [ + { + "name": "startCursor", + "description": "", + "args": [], + "type": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "endCursor", + "description": "", + "args": [], + "type": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "hasNextPage", + "description": "", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "Boolean", + "description": "The `Boolean` scalar type represents `true` or `false`.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "Review", + "description": "Represents a review for a movie", + "fields": [ + { + "name": "stars", + "description": "The number of stars this review gave, 1-5", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "commentary", + "description": "Comment about the movie", + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "UNION", + "name": "SearchResult", + "description": "", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": [ + { + "kind": "OBJECT", + "name": "Human", + "ofType": null + }, + { + "kind": "OBJECT", + "name": "Droid", + "ofType": null + }, + { + "kind": "OBJECT", + "name": "Starship", + "ofType": null + } + ] + }, + { + "kind": "OBJECT", + "name": "Human", + "description": "A humanoid creature from the Star Wars universe", + "fields": [ + { + "name": "id", + "description": "The ID of the human", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "name", + "description": "What this human calls themselves", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "homePlanet", + "description": "The home planet of the human, or null if unknown", + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "height", + "description": "Height in the preferred unit, default is meters", + "args": [ + { + "name": "unit", + "description": "", + "type": { + "kind": "ENUM", + "name": "LengthUnit", + "ofType": null + }, + "defaultValue": "METER" + } + ], + "type": { + "kind": "SCALAR", + "name": "Float", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "mass", + "description": "Mass in kilograms, or null if unknown", + "args": [], + "type": { + "kind": "SCALAR", + "name": "Float", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "friends", + "description": "This human's friends, or an empty list if they have none", + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "INTERFACE", + "name": "Character", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "friendsConnection", + "description": "The friends of the human exposed as a connection with edges", + "args": [ + { + "name": "first", + "description": "", + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + }, + "defaultValue": null + }, + { + "name": "after", + "description": "", + "type": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + }, + "defaultValue": null + } + ], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "FriendsConnection", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "appearsIn", + "description": "The movies this human appears in", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "ENUM", + "name": "Episode", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "starships", + "description": "A list of starships this person has piloted, or an empty list if none", + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "Starship", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [ + { + "kind": "INTERFACE", + "name": "Character", + "ofType": null + } + ], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "ENUM", + "name": "LengthUnit", + "description": "Units of height", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": [ + { + "name": "METER", + "description": "The standard unit around the world", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "FOOT", + "description": "Primarily used in the United States", + "isDeprecated": false, + "deprecationReason": null + } + ], + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "Float", + "description": "The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point). ", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "Starship", + "description": "", + "fields": [ + { + "name": "id", + "description": "The ID of the starship", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "name", + "description": "The name of the starship", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "length", + "description": "Length of the starship, along the longest axis", + "args": [ + { + "name": "unit", + "description": "", + "type": { + "kind": "ENUM", + "name": "LengthUnit", + "ofType": null + }, + "defaultValue": "METER" + } + ], + "type": { + "kind": "SCALAR", + "name": "Float", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "Droid", + "description": "An autonomous mechanical character in the Star Wars universe", + "fields": [ + { + "name": "id", + "description": "The ID of the droid", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "name", + "description": "What others call this droid", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "friends", + "description": "This droid's friends, or an empty list if they have none", + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "INTERFACE", + "name": "Character", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "friendsConnection", + "description": "The friends of the droid exposed as a connection with edges", + "args": [ + { + "name": "first", + "description": "", + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + }, + "defaultValue": null + }, + { + "name": "after", + "description": "", + "type": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + }, + "defaultValue": null + } + ], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "FriendsConnection", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "appearsIn", + "description": "The movies this droid appears in", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "ENUM", + "name": "Episode", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "primaryFunction", + "description": "This droid's primary function", + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [ + { + "kind": "INTERFACE", + "name": "Character", + "ofType": null + } + ], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "Mutation", + "description": "The mutation type, represents all updates we can make to our data", + "fields": [ + { + "name": "createReview", + "description": "", + "args": [ + { + "name": "episode", + "description": "", + "type": { + "kind": "ENUM", + "name": "Episode", + "ofType": null + }, + "defaultValue": null + }, + { + "name": "review", + "description": "", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "ReviewInput", + "ofType": null + } + }, + "defaultValue": null + } + ], + "type": { + "kind": "OBJECT", + "name": "Review", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "INPUT_OBJECT", + "name": "ReviewInput", + "description": "The input object sent when someone is creating a new review", + "fields": null, + "inputFields": [ + { + "name": "stars", + "description": "0-5 stars", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + } + }, + "defaultValue": null + }, + { + "name": "commentary", + "description": "Comment about the movie, optional", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "defaultValue": null + }, + { + "name": "favoriteColor", + "description": "Favorite color, optional", + "type": { + "kind": "INPUT_OBJECT", + "name": "ColorInput", + "ofType": null + }, + "defaultValue": null + } + ], + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "INPUT_OBJECT", + "name": "ColorInput", + "description": "The input object sent when passing a color", + "fields": null, + "inputFields": [ + { + "name": "red", + "description": "", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + } + }, + "defaultValue": null + }, + { + "name": "green", + "description": "", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + } + }, + "defaultValue": null + }, + { + "name": "blue", + "description": "", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + } + }, + "defaultValue": null + } + ], + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__Schema", + "description": "A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations.", + "fields": [ + { + "name": "types", + "description": "A list of all types supported by this server.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "queryType", + "description": "The type that query operations will be rooted at.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "mutationType", + "description": "If this server supports mutation, the type that mutation operations will be rooted at.", + "args": [], + "type": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "subscriptionType", + "description": "If this server support subscription, the type that subscription operations will be rooted at.", + "args": [], + "type": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "directives", + "description": "A list of all directives supported by this server.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Directive", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__Type", + "description": "The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum.\n\nDepending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name and description, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types.", + "fields": [ + { + "name": "kind", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "ENUM", + "name": "__TypeKind", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "name", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "fields", + "description": null, + "args": [ + { + "name": "includeDeprecated", + "description": null, + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + }, + "defaultValue": "false" + } + ], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Field", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "interfaces", + "description": null, + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "possibleTypes", + "description": null, + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "enumValues", + "description": null, + "args": [ + { + "name": "includeDeprecated", + "description": null, + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + }, + "defaultValue": "false" + } + ], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__EnumValue", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "inputFields", + "description": null, + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__InputValue", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "ofType", + "description": null, + "args": [], + "type": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "ENUM", + "name": "__TypeKind", + "description": "An enum describing what kind of type a given `__Type` is.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": [ + { + "name": "SCALAR", + "description": "Indicates this type is a scalar.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "OBJECT", + "description": "Indicates this type is an object. `fields` and `interfaces` are valid fields.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INTERFACE", + "description": "Indicates this type is an interface. `fields` and `possibleTypes` are valid fields.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "UNION", + "description": "Indicates this type is a union. `possibleTypes` is a valid field.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "ENUM", + "description": "Indicates this type is an enum. `enumValues` is a valid field.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INPUT_OBJECT", + "description": "Indicates this type is an input object. `inputFields` is a valid field.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "LIST", + "description": "Indicates this type is a list. `ofType` is a valid field.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "NON_NULL", + "description": "Indicates this type is a non-null. `ofType` is a valid field.", + "isDeprecated": false, + "deprecationReason": null + } + ], + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__Field", + "description": "Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type.", + "fields": [ + { + "name": "name", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "args", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__InputValue", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "type", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "isDeprecated", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "deprecationReason", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__InputValue", + "description": "Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value.", + "fields": [ + { + "name": "name", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "type", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "defaultValue", + "description": "A GraphQL-formatted string representing the default value for this input value.", + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__EnumValue", + "description": "One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string.", + "fields": [ + { + "name": "name", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "isDeprecated", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "deprecationReason", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__Directive", + "description": "A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.\n\nIn some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor.", + "fields": [ + { + "name": "name", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "locations", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "ENUM", + "name": "__DirectiveLocation", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "args", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__InputValue", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "onOperation", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": true, + "deprecationReason": "Use `locations`." + }, + { + "name": "onFragment", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": true, + "deprecationReason": "Use `locations`." + }, + { + "name": "onField", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": true, + "deprecationReason": "Use `locations`." + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "ENUM", + "name": "__DirectiveLocation", + "description": "A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": [ + { + "name": "QUERY", + "description": "Location adjacent to a query operation.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "MUTATION", + "description": "Location adjacent to a mutation operation.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "SUBSCRIPTION", + "description": "Location adjacent to a subscription operation.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "FIELD", + "description": "Location adjacent to a field.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "FRAGMENT_DEFINITION", + "description": "Location adjacent to a fragment definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "FRAGMENT_SPREAD", + "description": "Location adjacent to a fragment spread.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INLINE_FRAGMENT", + "description": "Location adjacent to an inline fragment.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "SCHEMA", + "description": "Location adjacent to a schema definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "SCALAR", + "description": "Location adjacent to a scalar definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "OBJECT", + "description": "Location adjacent to an object type definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "FIELD_DEFINITION", + "description": "Location adjacent to a field definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "ARGUMENT_DEFINITION", + "description": "Location adjacent to an argument definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INTERFACE", + "description": "Location adjacent to an interface definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "UNION", + "description": "Location adjacent to a union definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "ENUM", + "description": "Location adjacent to an enum definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "ENUM_VALUE", + "description": "Location adjacent to an enum value definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INPUT_OBJECT", + "description": "Location adjacent to an input object type definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INPUT_FIELD_DEFINITION", + "description": "Location adjacent to an input object field definition.", + "isDeprecated": false, + "deprecationReason": null + } + ], + "possibleTypes": null + } + ], + "directives": [ + { + "name": "skip", + "description": "Directs the executor to skip this field or fragment when the `if` argument is true.", + "locations": ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"], + "args": [ + { + "name": "if", + "description": "Skipped when true.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "defaultValue": null + } + ] + }, + { + "name": "include", + "description": "Directs the executor to include this field or fragment only when the `if` argument is true.", + "locations": ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"], + "args": [ + { + "name": "if", + "description": "Included when true.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "defaultValue": null + } + ] + }, + { + "name": "deprecated", + "description": "Marks an element of a GraphQL schema as no longer supported.", + "locations": ["FIELD_DEFINITION", "ENUM_VALUE"], + "args": [ + { + "name": "reason", + "description": "Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted in [Markdown](https://daringfireball.net/projects/markdown/).", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "defaultValue": "\"No longer supported\"" + } + ] + } + ] + } + } +} diff --git a/dev-test/gql-tag-operations-masking-star-wars/src/index.tsx b/dev-test/gql-tag-operations-masking-star-wars/src/index.tsx new file mode 100644 index 00000000000..e0690816d06 --- /dev/null +++ b/dev-test/gql-tag-operations-masking-star-wars/src/index.tsx @@ -0,0 +1,60 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import React from 'react'; +import { gql, FragmentType, useFragment } from '../gql'; +import { useQuery } from 'urql'; + +const HeroDetailsWithFragment = gql(/* GraphQL */ ` + query HeroDetailsWithFragment($episode: Episode) { + hero(episode: $episode) { + ...HeroDetails + } + } +`); + +const HeroDetailsFragment = gql(/* GraphQL */ ` + fragment HeroDetails on Character { + __typename + name + ... on Human { + height + } + ... on Droid { + primaryFunction + } + } +`); + +const HeroDetails = (props: { data: FragmentType }) => { + // masking union type + const hero = useFragment(HeroDetailsFragment, props.data); + + switch (hero.__typename) { + case 'Droid': + return ( +
+

Name: {hero.name}

+

Primary function: {hero.primaryFunction}

+
+ ); + case 'Human': + return ( +
+

Name: {hero.name}

+

Height: {hero.height}

+
+ ); + default: { + // unreachable path + const _exhaustiveCheck: never = hero; + return null; + } + } +}; + +const HeroDetailsApp = () => { + const [query] = useQuery({ query: HeroDetailsWithFragment }); + + if (query.data?.hero == null) return null; + + return ; +}; diff --git a/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts b/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts index 6a364df9b8f..e7667b59198 100644 --- a/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts +++ b/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts @@ -609,7 +609,9 @@ export class SelectionSetToObject { + const schema = buildSchema(/* GraphQL */ ` + type Character { + name: String + } + + type Jedi { + name: String + side: String + } + + type Droid { + model: String + } + + union People = Character | Jedi | Droid + + type Query { + people: People! + } + `); + + const query = parse(/* GraphQL */ ` + query GetPeople { + people { + ...PeopleInfo + } + } + `); + + const fragment = parse(/* GraphQL */ ` + fragment PeopleInfo on People { + ... on Character { + name + } + + ... on Jedi { + side + } + + ... on Droid { + model + } + } + `); + + const { content } = await plugin( + schema, + [ + { location: '', document: query }, + { location: '', document: fragment }, + ], + { inlineFragmentTypes: 'mask' }, + { outputFile: 'graphql.ts' } + ); + + expect(content).toMatchInlineSnapshot(` + "export type GetPeopleQueryVariables = Exact<{ [key: string]: never; }>; + + + export type GetPeopleQuery = { __typename?: 'Query', people: ( + { __typename?: 'Character' } + & { ' $fragmentRefs': { 'PeopleInfo_Character_Fragment': PeopleInfo_Character_Fragment } } + ) | ( + { __typename?: 'Jedi' } + & { ' $fragmentRefs': { 'PeopleInfo_Jedi_Fragment': PeopleInfo_Jedi_Fragment } } + ) | ( + { __typename?: 'Droid' } + & { ' $fragmentRefs': { 'PeopleInfo_Droid_Fragment': PeopleInfo_Droid_Fragment } } + ) }; + + type PeopleInfo_Character_Fragment = { __typename?: 'Character', name?: string | null } & { ' $fragmentName': 'PeopleInfo_Character_Fragment' }; + + type PeopleInfo_Jedi_Fragment = { __typename?: 'Jedi', side?: string | null } & { ' $fragmentName': 'PeopleInfo_Jedi_Fragment' }; + + type PeopleInfo_Droid_Fragment = { __typename?: 'Droid', model?: string | null } & { ' $fragmentName': 'PeopleInfo_Droid_Fragment' }; + + export type PeopleInfoFragment = PeopleInfo_Character_Fragment | PeopleInfo_Jedi_Fragment | PeopleInfo_Droid_Fragment; + " + `); + }); }); describe('conditional directives handling', () => { diff --git a/packages/presets/gql-tag-operations/tests/fixtures/union-fragment.ts b/packages/presets/gql-tag-operations/tests/fixtures/union-fragment.ts new file mode 100644 index 00000000000..c50d81abb0a --- /dev/null +++ b/packages/presets/gql-tag-operations/tests/fixtures/union-fragment.ts @@ -0,0 +1,23 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ + +//@ts-ignore +const Query = gql(/* GraphQL */ ` + query Foo { + foo { + ...Foo + } + } +`); + +//@ts-ignore +const Fragment = gql(/* GraphQL */ ` + fragment Foo on Foo { + __typename + ... on Bar { + stringValue + } + ... on Baz { + intValue + } + } +`);