Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: resolve introspection from url #26

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/five-dancers-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphqlsp': minor
---

Add ability to specify a URL for your schema, GraphQLSP will then fetch the introspection from the specified URL
237 changes: 174 additions & 63 deletions example/src/index.generated.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
export type Maybe<T> = T | null;
export type InputMaybe<T> = Maybe<T>;
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 K]?: Maybe<T[SubKey]> };
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
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 K]?: Maybe<T[SubKey]>;
};
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
[SubKey in K]: Maybe<T[SubKey]>;
};
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: string;
Expand All @@ -13,18 +19,33 @@ export type Scalars = {
Float: number;
};

/** Elemental property associated with either a Pokémon or one of their moves. */
export type PokemonType =
| 'Grass'
| 'Poison'
| 'Fire'
| 'Flying'
| 'Water'
| 'Bug'
| 'Normal'
| 'Electric'
| 'Ground'
| 'Fairy'
| 'Fighting'
| 'Psychic'
| 'Rock'
| 'Steel'
| 'Ice'
| 'Ghost'
| 'Dragon'
| 'Dark';

/** Move a Pokémon can perform with the associated damage and type. */
export type Attack = {
__typename?: 'Attack';
damage?: Maybe<Scalars['Int']>;
name?: Maybe<Scalars['String']>;
type?: Maybe<PokemonType>;
};

export type AttacksConnection = {
__typename?: 'AttacksConnection';
fast?: Maybe<Array<Maybe<Attack>>>;
special?: Maybe<Array<Maybe<Attack>>>;
damage?: Maybe<Scalars['Int']>;
};

/** Requirement that prevents an evolution through regular means of levelling up. */
Expand All @@ -34,88 +55,178 @@ export type EvolutionRequirement = {
name?: Maybe<Scalars['String']>;
};

export type PokemonDimension = {
__typename?: 'PokemonDimension';
minimum?: Maybe<Scalars['String']>;
maximum?: Maybe<Scalars['String']>;
};

export type AttacksConnection = {
__typename?: 'AttacksConnection';
fast?: Maybe<Array<Maybe<Attack>>>;
special?: Maybe<Array<Maybe<Attack>>>;
};

export type Pokemon = {
__typename?: 'Pokemon';
attacks?: Maybe<AttacksConnection>;
/** @deprecated And this is the reason why */
id: Scalars['ID'];
name: Scalars['String'];
classification?: Maybe<Scalars['String']>;
types?: Maybe<Array<Maybe<PokemonType>>>;
resistant?: Maybe<Array<Maybe<PokemonType>>>;
weaknesses?: Maybe<Array<Maybe<PokemonType>>>;
evolutionRequirements?: Maybe<Array<Maybe<EvolutionRequirement>>>;
evolutions?: Maybe<Array<Maybe<Pokemon>>>;
weight?: Maybe<PokemonDimension>;
height?: Maybe<PokemonDimension>;
attacks?: Maybe<AttacksConnection>;
/** Likelihood of an attempt to catch a Pokémon to fail. */
fleeRate?: Maybe<Scalars['Float']>;
height?: Maybe<PokemonDimension>;
id: Scalars['ID'];
/** Maximum combat power a Pokémon may achieve at max level. */
maxCP?: Maybe<Scalars['Int']>;
/** Maximum health points a Pokémon may achieve at max level. */
maxHP?: Maybe<Scalars['Int']>;
name: Scalars['String'];
resistant?: Maybe<Array<Maybe<PokemonType>>>;
types?: Maybe<Array<Maybe<PokemonType>>>;
weaknesses?: Maybe<Array<Maybe<PokemonType>>>;
weight?: Maybe<PokemonDimension>;
};

export type PokemonDimension = {
__typename?: 'PokemonDimension';
maximum?: Maybe<Scalars['String']>;
minimum?: Maybe<Scalars['String']>;
evolutions?: Maybe<Array<Maybe<Pokemon>>>;
};

/** Elemental property associated with either a Pokémon or one of their moves. */
export type PokemonType =
| 'Bug'
| 'Dark'
| 'Dragon'
| 'Electric'
| 'Fairy'
| 'Fighting'
| 'Fire'
| 'Flying'
| 'Ghost'
| 'Grass'
| 'Ground'
| 'Ice'
| 'Normal'
| 'Poison'
| 'Psychic'
| 'Rock'
| 'Steel'
| 'Water';

export type Query = {
__typename?: 'Query';
/** Get a single Pokémon by its ID, a three character long identifier padded with zeroes */
pokemon?: Maybe<Pokemon>;
/** List out all Pokémon, optionally in pages */
pokemons?: Maybe<Array<Maybe<Pokemon>>>;
/** Get a single Pokémon by its ID, a three character long identifier padded with zeroes */
pokemon?: Maybe<Pokemon>;
};


export type QueryPokemonArgs = {
id: Scalars['ID'];
};


export type QueryPokemonsArgs = {
limit?: InputMaybe<Scalars['Int']>;
skip?: InputMaybe<Scalars['Int']>;
};

export type PokemonsQueryVariables = Exact<{ [key: string]: never; }>;
export type QueryPokemonArgs = {
id: Scalars['ID'];
};

export type PokemonsQueryVariables = Exact<{ [key: string]: never }>;

export type PokemonsQuery = { __typename?: 'Query', pokemons?: Array<{ __typename: 'Pokemon', id: string, name: string } | null> | null };
export type PokemonsQuery = {
__typename?: 'Query';
pokemons?: Array<{
__typename: 'Pokemon';
id: string;
name: string;
} | null> | null;
};

export type PokemonFieldsFragment = { __typename?: 'Pokemon', id: string, name: string };
export type PokemonFieldsFragment = {
__typename?: 'Pokemon';
id: string;
name: string;
};

export type PokemonQueryVariables = Exact<{
id: Scalars['ID'];
}>;

export type PokemonQuery = {
__typename?: 'Query';
pokemon?: { __typename: 'Pokemon'; id: string; name: string } | null;
};

export type PokemonQuery = { __typename?: 'Query', pokemon?: { __typename: 'Pokemon', id: string, name: string } | null };

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>;
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>;
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>;
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>;
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>;
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>;
22 changes: 12 additions & 10 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"compilerOptions": {
"plugins": [{
"name": "plugin",
"schema": "./schema.graphql"
}],
"plugins": [
{
"name": "plugin",
"schema": "https://trygql.formidable.dev/graphql/basic-pokedex"
}
],
/* Visit https://aka.ms/tsconfig to read more about this file */

/* Projects */
Expand All @@ -15,7 +17,7 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
Expand All @@ -29,7 +31,7 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */

/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
"module": "commonjs" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
Expand Down Expand Up @@ -75,12 +77,12 @@
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,

/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
Expand All @@ -102,6 +104,6 @@

/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
10 changes: 9 additions & 1 deletion example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,13 @@ node-fetch@2.6.7:
dependencies:
whatwg-url "^5.0.0"

node-fetch@^2.0.0:
version "2.6.9"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.9.tgz#7c7f744b5cc6eb5fd404e0c7a9fec630a55657e6"
integrity sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==
dependencies:
whatwg-url "^5.0.0"

node-int64@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"
Expand Down Expand Up @@ -1316,13 +1323,14 @@ picocolors@^1.0.0:
integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==

"plugin@file:..":
version "1.0.0"
version "0.1.0"
dependencies:
"@graphql-codegen/core" "^2.6.8"
"@graphql-codegen/typed-document-node" "^2.3.10"
"@graphql-codegen/typescript" "^2.8.5"
"@graphql-codegen/typescript-operations" "^2.5.10"
graphql-language-service "^5.0.6"
node-fetch "^2.0.0"

promise@^7.1.1:
version "7.3.1"
Expand Down
Loading