Mirror: TypeScript LSP plugin that finds GraphQL documents in your code and provides diagnostics, auto-complete and hover-information.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix crash

+57 -79
+8
example/src/Pokemon.ts
··· 1 + import { gql } from '@urql/core'; 2 + 3 + export const PokemonFields = gql` 4 + fragment pokemonFields on Pokemon { 5 + id 6 + name 7 + } 8 + ` as typeof import('./Pokemon.generated').PokemonFieldsFragmentDoc
+19 -20
example/src/fragment.generated.ts example/src/Pokemon.generated.ts
··· 62 62 }; 63 63 64 64 /** Elemental property associated with either a Pokémon or one of their moves. */ 65 - export enum PokemonType { 66 - Bug = 'Bug', 67 - Dark = 'Dark', 68 - Dragon = 'Dragon', 69 - Electric = 'Electric', 70 - Fairy = 'Fairy', 71 - Fighting = 'Fighting', 72 - Fire = 'Fire', 73 - Flying = 'Flying', 74 - Ghost = 'Ghost', 75 - Grass = 'Grass', 76 - Ground = 'Ground', 77 - Ice = 'Ice', 78 - Normal = 'Normal', 79 - Poison = 'Poison', 80 - Psychic = 'Psychic', 81 - Rock = 'Rock', 82 - Steel = 'Steel', 83 - Water = 'Water' 84 - } 65 + export type PokemonType = 66 + | 'Bug' 67 + | 'Dark' 68 + | 'Dragon' 69 + | 'Electric' 70 + | 'Fairy' 71 + | 'Fighting' 72 + | 'Fire' 73 + | 'Flying' 74 + | 'Ghost' 75 + | 'Grass' 76 + | 'Ground' 77 + | 'Ice' 78 + | 'Normal' 79 + | 'Poison' 80 + | 'Psychic' 81 + | 'Rock' 82 + | 'Steel' 83 + | 'Water'; 85 84 86 85 export type Query = { 87 86 __typename?: 'Query';
-20
example/src/fragment.ts
··· 1 - import { gql } from '@urql/core' 2 - 3 - export const PokemonFields = gql` 4 - fragment pokemonFields on Pokemon { 5 - id 6 - name 7 - } 8 - ` as typeof import('./fragment.generated').PokemonFieldsFragmentDoc 9 - // TODO: how to type 10 - // export const PokemonFields = gql` 11 - // fragment pokemonFields on Pokemon { 12 - // id 13 - // name 14 - // } 15 - 16 - // fragment morePokemonFields on Pokemon { 17 - // id 18 - // name 19 - // } 20 - // ` as typeof import('./fragment.generated').PokemonsDocument
+5 -11
example/src/index.generated.ts
··· 104 104 export type PokemonsQueryVariables = Exact<{ [key: string]: never; }>; 105 105 106 106 107 - export type PokemonsQuery = { __typename?: 'Query', pokemons?: Array<{ __typename?: 'Pokemon', id: string, name: string } | null> | null }; 107 + export type PokemonsQuery = { __typename?: 'Query', pokemons?: Array<{ __typename: 'Pokemon', id: string, name: string } | null> | null }; 108 108 109 109 export type PokemonFieldsFragment = { __typename?: 'Pokemon', id: string, name: string }; 110 110 111 - export type PokemonQueryVariables = Exact<{ [key: string]: never; }>; 112 - 113 - 114 - export type PokemonQuery = { __typename?: 'Query', pokemon?: { __typename?: 'Pokemon', id: string, name: string } | null }; 115 - 116 - export type DonkemonQueryVariables = Exact<{ 111 + export type PokemonQueryVariables = Exact<{ 117 112 id: Scalars['ID']; 118 113 }>; 119 114 120 115 121 - export type DonkemonQuery = { __typename?: 'Query', pokemon?: { __typename?: 'Pokemon', id: string } | null }; 116 + export type PokemonQuery = { __typename?: 'Query', pokemon?: { __typename: 'Pokemon', id: string, name: string } | null }; 122 117 123 118 export const PokemonFieldsFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"pokemonFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Pokemon"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]} as unknown as DocumentNode<PokemonFieldsFragment, unknown>; 124 - export const PokemonsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Pokemons"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"pokemons"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]} as unknown as DocumentNode<PokemonsQuery, PokemonsQueryVariables>; 125 - export const PokemonDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Pokemon"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"pokemon"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"StringValue","value":"1","block":false}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"FragmentSpread","name":{"kind":"Name","value":"pokemonFields"}}]}}]}},...PokemonFieldsFragmentDoc.definitions]} as unknown as DocumentNode<PokemonQuery, PokemonQueryVariables>; 126 - export const DonkemonDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Donkemon"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"pokemon"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}}]}}]} as unknown as DocumentNode<DonkemonQuery, DonkemonQueryVariables>; 119 + export const PokemonsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Pokemons"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"pokemons"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"FragmentSpread","name":{"kind":"Name","value":"pokemonFields"}},{"kind":"Field","name":{"kind":"Name","value":"__typename"}}]}}]}},...PokemonFieldsFragmentDoc.definitions]} as unknown as DocumentNode<PokemonsQuery, PokemonsQueryVariables>; 120 + export const PokemonDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Pokemon"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"pokemon"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"__typename"}}]}}]}}]} as unknown as DocumentNode<PokemonQuery, PokemonQueryVariables>;
+20 -26
example/src/index.ts
··· 1 - import { createClient, gql } from '@urql/core' 2 - import { PokemonFields } from './fragment' 3 - 4 - // testing stuffzzzzzzzz 1 + import { gql, createClient } from '@urql/core'; 2 + import { PokemonFields } from './Pokemon'; 5 3 6 - const Pokemons = gql` 4 + const PokemonsQuery = gql` 7 5 query Pokemons { 8 6 pokemons { 9 7 id 10 - name 8 + name 9 + ...pokemonFields 10 + __typename 11 11 } 12 12 } 13 13 14 14 ${PokemonFields} 15 15 ` as typeof import('./index.generated').PokemonsDocument 16 16 17 - const Pokemon = gql` 18 - query Pokemon { 19 - pokemon(id: "1") { 20 - id 21 - name 22 - ...pokemonFields 23 - } 24 - } 17 + const client = createClient({ 18 + url: '', 19 + }) 25 20 26 - ${PokemonFields} 27 - ` as typeof import('./index.generated').PokemonDocument 21 + client.query(PokemonsQuery).toPromise().then(result => { 22 + result.data?.pokemons; 23 + }) 28 24 29 - const Donkemon = gql` 30 - query Donkemon ($id: ID!) { 25 + const PokemonQuery = gql` 26 + query Pokemon($id: ID!) { 31 27 pokemon(id: $id) { 32 28 id 29 + name 30 + __typename 33 31 } 34 32 } 35 - ` as typeof import('./index.generated').DonkemonDocument 36 - const urqlClient = createClient({ 37 - url: '', 38 - exchanges: [] 39 - }); 33 + ` as typeof import('./index.generated').PokemonDocument 40 34 41 - urqlClient.query(Pokemons).toPromise().then(result => { 42 - result.data?.pokemons; 43 - }); 35 + client.query(PokemonQuery, { id: '' }).toPromise().then(result => { 36 + result.data?.pokemon; 37 + })
+5 -2
src/index.ts
··· 236 236 237 237 const suggestions = getAutocompleteSuggestions(schema.current, text, new Cursor(foundToken.line, foundToken.start)) 238 238 239 - const parsed = parse(text); 240 - const fragments = parsed.definitions.filter(x => x.kind === Kind.FRAGMENT_DEFINITION) as Array<FragmentDefinitionNode> 239 + let fragments: Array<FragmentDefinitionNode> = [] 240 + try { 241 + const parsed = parse(text); 242 + fragments = parsed.definitions.filter(x => x.kind === Kind.FRAGMENT_DEFINITION) as Array<FragmentDefinitionNode> 243 + } catch (e) {} 241 244 242 245 const result: ts.WithMetadata<ts.CompletionInfo> = { 243 246 isGlobalCompletion: false,