Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Dec 20, 2023
1 parent d8f1ba8 commit c8bbc89
Show file tree
Hide file tree
Showing 10 changed files with 610 additions and 476 deletions.
4 changes: 3 additions & 1 deletion packages/example-external-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
"dependencies": {
"@graphql-typed-document-node/core": "^3.2.0",
"@urql/core": "^3.0.0",
"graphql": "^16.8.1"
"graphql": "^16.8.1",
"urql": "^4.0.6"
},
"devDependencies": {
"@0no-co/graphqlsp": "file:../graphqlsp",
"@graphql-codegen/cli": "^5.0.0",
"@graphql-codegen/client-preset": "^4.1.0",
"@types/react": "^18.2.45",
"ts-node": "^10.9.1",
"typescript": "^5.3.3"
}
Expand Down
6 changes: 0 additions & 6 deletions packages/example-external-generator/src/Pokemon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ export const PokemonFields = graphql(`
}
`)

export const WeakFields = graphql(`
fragment weaknessFields on Pokemon {
weaknesses
}
`)

export const Pokemon = (data: any) => {
const pokemon = useFragment(PokemonFields, data);
return `hi ${pokemon.name}`;
Expand Down
30 changes: 3 additions & 27 deletions packages/example-external-generator/src/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
const documents = {
'\n fragment pokemonFields on Pokemon {\n id\n name\n attacks {\n fast {\n damage\n name\n }\n }\n }\n':
types.PokemonFieldsFragmentDoc,
'\n fragment weaknessFields on Pokemon {\n weaknesses\n }\n':
types.WeaknessFieldsFragmentDoc,
'\n query Pok($limit: Int!) {\n pokemons(limit: $limit) {\n id\n name\n fleeRate\n classification\n ...pokemonFields\n ...weaknessFields\n __typename\n }\n }\n':
types.PokDocument,
'\n query Po($id: ID!) {\n pokemon(id: $id) {\n id\n fleeRate\n __typename\n }\n }\n':
'\n query Po($id: ID!) {\n pokemon(id: $id) {\n id\n fleeRate\n ...pokemonFields\n attacks {\n special {\n name\n damage\n }\n }\n weight {\n minimum\n maximum\n }\n name\n __typename\n }\n }\n':
types.PoDocument,
'\n query PokemonsAreAwesome {\n pokemons {\n id\n }\n }\n':
types.PokemonsAreAwesomeDocument,
};

/**
Expand All @@ -49,26 +43,8 @@ export function graphql(
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(
source: '\n fragment weaknessFields on Pokemon {\n weaknesses\n }\n'
): (typeof documents)['\n fragment weaknessFields on Pokemon {\n weaknesses\n }\n'];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(
source: '\n query Pok($limit: Int!) {\n pokemons(limit: $limit) {\n id\n name\n fleeRate\n classification\n ...pokemonFields\n ...weaknessFields\n __typename\n }\n }\n'
): (typeof documents)['\n query Pok($limit: Int!) {\n pokemons(limit: $limit) {\n id\n name\n fleeRate\n classification\n ...pokemonFields\n ...weaknessFields\n __typename\n }\n }\n'];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(
source: '\n query Po($id: ID!) {\n pokemon(id: $id) {\n id\n fleeRate\n __typename\n }\n }\n'
): (typeof documents)['\n query Po($id: ID!) {\n pokemon(id: $id) {\n id\n fleeRate\n __typename\n }\n }\n'];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(
source: '\n query PokemonsAreAwesome {\n pokemons {\n id\n }\n }\n'
): (typeof documents)['\n query PokemonsAreAwesome {\n pokemons {\n id\n }\n }\n'];
source: '\n query Po($id: ID!) {\n pokemon(id: $id) {\n id\n fleeRate\n ...pokemonFields\n attacks {\n special {\n name\n damage\n }\n }\n weight {\n minimum\n maximum\n }\n name\n __typename\n }\n }\n'
): (typeof documents)['\n query Po($id: ID!) {\n pokemon(id: $id) {\n id\n fleeRate\n ...pokemonFields\n attacks {\n special {\n name\n damage\n }\n }\n weight {\n minimum\n maximum\n }\n name\n __typename\n }\n }\n'];

export function graphql(source: string) {
return (documents as any)[source] ?? {};
Expand Down
231 changes: 69 additions & 162 deletions packages/example-external-generator/src/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,52 +131,35 @@ export type PokemonFieldsFragment = {
} | null;
} & { ' $fragmentName'?: 'PokemonFieldsFragment' };

export type WeaknessFieldsFragment = {
__typename?: 'Pokemon';
weaknesses?: Array<PokemonType | null> | null;
} & { ' $fragmentName'?: 'WeaknessFieldsFragment' };

export type PokQueryVariables = Exact<{
limit: Scalars['Int']['input'];
export type PoQueryVariables = Exact<{
id: Scalars['ID']['input'];
}>;

export type PokQuery = {
export type PoQuery = {
__typename?: 'Query';
pokemons?: Array<
pokemon?:
| ({
__typename: 'Pokemon';
id: string;
name: string;
fleeRate?: number | null;
classification?: string | null;
name: string;
attacks?: {
__typename?: 'AttacksConnection';
special?: Array<{
__typename?: 'Attack';
name?: string | null;
damage?: number | null;
} | null> | null;
} | null;
weight?: {
__typename?: 'PokemonDimension';
minimum?: string | null;
maximum?: string | null;
} | null;
} & {
' $fragmentRefs'?: {
PokemonFieldsFragment: PokemonFieldsFragment;
WeaknessFieldsFragment: WeaknessFieldsFragment;
};
' $fragmentRefs'?: { PokemonFieldsFragment: PokemonFieldsFragment };
})
| null
> | null;
};

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

export type PoQuery = {
__typename?: 'Query';
pokemon?: {
__typename: 'Pokemon';
id: string;
fleeRate?: number | null;
} | null;
};

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

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

export const PokemonFieldsFragmentDoc = {
Expand Down Expand Up @@ -222,42 +205,20 @@ export const PokemonFieldsFragmentDoc = {
},
],
} as unknown as DocumentNode<PokemonFieldsFragment, unknown>;
export const WeaknessFieldsFragmentDoc = {
kind: 'Document',
definitions: [
{
kind: 'FragmentDefinition',
name: { kind: 'Name', value: 'weaknessFields' },
typeCondition: {
kind: 'NamedType',
name: { kind: 'Name', value: 'Pokemon' },
},
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'weaknesses' } },
],
},
},
],
} as unknown as DocumentNode<WeaknessFieldsFragment, unknown>;
export const PokDocument = {
export const PoDocument = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
name: { kind: 'Name', value: 'Pok' },
name: { kind: 'Name', value: 'Po' },
variableDefinitions: [
{
kind: 'VariableDefinition',
variable: {
kind: 'Variable',
name: { kind: 'Name', value: 'limit' },
},
variable: { kind: 'Variable', name: { kind: 'Name', value: 'id' } },
type: {
kind: 'NonNullType',
type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } },
type: { kind: 'NamedType', name: { kind: 'Name', value: 'ID' } },
},
},
],
Expand All @@ -266,35 +227,70 @@ export const PokDocument = {
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'pokemons' },
name: { kind: 'Name', value: 'pokemon' },
arguments: [
{
kind: 'Argument',
name: { kind: 'Name', value: 'limit' },
name: { kind: 'Name', value: 'id' },
value: {
kind: 'Variable',
name: { kind: 'Name', value: 'limit' },
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: 'fleeRate' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'classification' },
},
{
kind: 'FragmentSpread',
name: { kind: 'Name', value: 'pokemonFields' },
},
{
kind: 'FragmentSpread',
name: { kind: 'Name', value: 'weaknessFields' },
kind: 'Field',
name: { kind: 'Name', value: 'attacks' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'special' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'name' },
},
{
kind: 'Field',
name: { kind: 'Name', value: 'damage' },
},
],
},
},
],
},
},
{
kind: 'Field',
name: { kind: 'Name', value: 'weight' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'minimum' },
},
{
kind: 'Field',
name: { kind: 'Name', value: 'maximum' },
},
],
},
},
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
],
},
Expand Down Expand Up @@ -340,94 +336,5 @@ export const PokDocument = {
],
},
},
{
kind: 'FragmentDefinition',
name: { kind: 'Name', value: 'weaknessFields' },
typeCondition: {
kind: 'NamedType',
name: { kind: 'Name', value: 'Pokemon' },
},
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'weaknesses' } },
],
},
},
],
} as unknown as DocumentNode<PokQuery, PokQueryVariables>;
export const PoDocument = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
name: { kind: 'Name', value: 'Po' },
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: 'fleeRate' } },
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
],
},
},
],
},
},
],
} as unknown as DocumentNode<PoQuery, PoQueryVariables>;
export const PokemonsAreAwesomeDocument = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
name: { kind: 'Name', value: 'PokemonsAreAwesome' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'pokemons' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
],
},
},
],
},
},
],
} as unknown as DocumentNode<
PokemonsAreAwesomeQuery,
PokemonsAreAwesomeQueryVariables
>;
Loading

0 comments on commit c8bbc89

Please sign in to comment.