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

[Proof of concept] Custom key #189

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.idea/*
build
node_modules
test
src/**.js
Expand Down
27 changes: 27 additions & 0 deletions build/main/config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { RawClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-common';
/**
* @description This plugin generates [`graphql-request`](https://www.npmjs.com/package/graphql-request) ready-to-use SDK, which is fully-typed.
*/
export interface RawSWRPluginConfig extends RawClientSideBasePluginConfig {
/**
* @description By default the `request` method return the `data` or `errors` key from the response. If you need to access the `extensions` key you can use the `rawRequest` method.
* @default false
*
* @exampleMarkdown
* ```yml
* generates:
* path/to/file.ts:
* plugins:
* - typescript
* - typescript-operations
* - typescript-graphql-request
* - graphql-codegen-plugin-typescript-swr
* config:
* rawRequest: true
* ```
*/
rawRequest?: boolean;
excludeQueries?: string | string[];
useSWRInfinite?: string | string[];
autogenSWRKey?: boolean;
}
3 changes: 3 additions & 0 deletions build/main/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions build/main/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { PluginValidateFn, PluginFunction } from '@graphql-codegen/plugin-helpers';
import { RawSWRPluginConfig } from './config';
import { SWRVisitor } from './visitor';
export declare const plugin: PluginFunction<RawSWRPluginConfig>;
export declare const validate: PluginValidateFn<any>;
export { SWRVisitor };
34 changes: 34 additions & 0 deletions build/main/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions build/main/visitor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment, ParsedConfig } from '@graphql-codegen/visitor-plugin-common';
import { GraphQLSchema, OperationDefinitionNode } from 'graphql';
import { RawSWRPluginConfig } from './config';
export interface SWRPluginConfig extends ClientSideBasePluginConfig {
rawRequest: boolean;
excludeQueries: string | string[];
useSWRInfinite: string | string[];
autogenSWRKey: boolean;
}
export interface Operation {
node: OperationDefinitionNode;
documentVariableName: string;
operationType: string;
operationResultType: string;
operationVariablesTypes: string;
}
export interface ComposeQueryHandlerConfig {
autogenKey: SWRPluginConfig['autogenSWRKey'];
infinite: boolean;
rawRequest: SWRPluginConfig['rawRequest'];
typesPrefix: ParsedConfig['typesPrefix'];
typesSuffix: ParsedConfig['typesSuffix'];
}
export declare class SWRVisitor extends ClientSideBaseVisitor<RawSWRPluginConfig, SWRPluginConfig> {
private _operationsToInclude;
private _enabledInfinite;
constructor(schema: GraphQLSchema, fragments: LoadedFragment[], rawConfig: RawSWRPluginConfig);
protected buildOperation(node: OperationDefinitionNode, documentVariableName: string, operationType: string, operationResultType: string, operationVariablesTypes: string): string;
get sdkContent(): string;
}
Loading