add codegen to graphql modules / yoga template
This commit is contained in:
24
web/other/graphql-modules-yoga-prisma-starter/codegen.ts
Normal file
24
web/other/graphql-modules-yoga-prisma-starter/codegen.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { CodegenConfig } from "@graphql-codegen/cli";
|
||||
|
||||
const config: CodegenConfig = {
|
||||
schema: "./src/modules/**/typedefs/*.graphql",
|
||||
generates: {
|
||||
"./src/modules/": {
|
||||
preset: "graphql-modules",
|
||||
presetConfig: {
|
||||
baseTypesPath: "../gql/graphql.ts",
|
||||
filename: "module-types.ts",
|
||||
},
|
||||
plugins: [
|
||||
{
|
||||
add: {
|
||||
content: "/* eslint-disable */",
|
||||
},
|
||||
},
|
||||
"typescript",
|
||||
"typescript-resolvers",
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
export default config;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,8 @@
|
||||
"scripts": {
|
||||
"dev": "cross-env NODE_ENV=development ts-node-dev --exit-child --respawn src/main.ts",
|
||||
"start": "ts-node src/main.ts",
|
||||
"generate": "prisma generate"
|
||||
"generate": "prisma generate",
|
||||
"codegen": "graphql-codegen"
|
||||
},
|
||||
"keywords": [
|
||||
"graphql",
|
||||
@@ -18,17 +19,23 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@envelop/graphql-modules": "^6.0.0",
|
||||
"@graphql-tools/load-files": "^7.0.0",
|
||||
"@prisma/client": "^5.15.0",
|
||||
"graphql": "^16.8.1",
|
||||
"graphql-modules": "^2.3.0",
|
||||
"graphql-yoga": "^5.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@graphql-codegen/cli": "^5.0.2",
|
||||
"@graphql-codegen/graphql-modules-preset": "^4.0.7",
|
||||
"@graphql-codegen/typescript": "^4.0.7",
|
||||
"@graphql-codegen/typescript-resolvers": "^4.1.0",
|
||||
"@parcel/watcher": "^2.4.1",
|
||||
"@types/node": "18.16.16",
|
||||
"cross-env": "7.0.3",
|
||||
"prisma": "^5.15.0",
|
||||
"ts-node": "10.9.1",
|
||||
"ts-node-dev": "2.0.0",
|
||||
"typescript": "5.1.6"
|
||||
"typescript": "^5.1.6"
|
||||
}
|
||||
}
|
||||
|
||||
148
web/other/graphql-modules-yoga-prisma-starter/src/gql/graphql.ts
Normal file
148
web/other/graphql-modules-yoga-prisma-starter/src/gql/graphql.ts
Normal file
@@ -0,0 +1,148 @@
|
||||
/* eslint-disable */
|
||||
import { GraphQLResolveInfo } from 'graphql';
|
||||
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 MakeEmpty<T extends { [key: string]: unknown }, K extends keyof T> = { [_ in K]?: never };
|
||||
export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
|
||||
/** All built-in and custom scalars, mapped to their actual values */
|
||||
export type Scalars = {
|
||||
ID: { input: string; output: string; }
|
||||
String: { input: string; output: string; }
|
||||
Boolean: { input: boolean; output: boolean; }
|
||||
Int: { input: number; output: number; }
|
||||
Float: { input: number; output: number; }
|
||||
};
|
||||
|
||||
export type Mutation = {
|
||||
__typename?: 'Mutation';
|
||||
setMessage?: Maybe<Scalars['String']['output']>;
|
||||
};
|
||||
|
||||
|
||||
export type MutationSetMessageArgs = {
|
||||
message?: InputMaybe<Scalars['String']['input']>;
|
||||
};
|
||||
|
||||
export type Query = {
|
||||
__typename?: 'Query';
|
||||
world: World;
|
||||
};
|
||||
|
||||
export type World = {
|
||||
__typename?: 'World';
|
||||
x: Scalars['Int']['output'];
|
||||
y: Scalars['Int']['output'];
|
||||
};
|
||||
|
||||
|
||||
|
||||
export type ResolverTypeWrapper<T> = Promise<T> | T;
|
||||
|
||||
|
||||
export type ResolverWithResolve<TResult, TParent, TContext, TArgs> = {
|
||||
resolve: ResolverFn<TResult, TParent, TContext, TArgs>;
|
||||
};
|
||||
export type Resolver<TResult, TParent = {}, TContext = {}, TArgs = {}> = ResolverFn<TResult, TParent, TContext, TArgs> | ResolverWithResolve<TResult, TParent, TContext, TArgs>;
|
||||
|
||||
export type ResolverFn<TResult, TParent, TContext, TArgs> = (
|
||||
parent: TParent,
|
||||
args: TArgs,
|
||||
context: TContext,
|
||||
info: GraphQLResolveInfo
|
||||
) => Promise<TResult> | TResult;
|
||||
|
||||
export type SubscriptionSubscribeFn<TResult, TParent, TContext, TArgs> = (
|
||||
parent: TParent,
|
||||
args: TArgs,
|
||||
context: TContext,
|
||||
info: GraphQLResolveInfo
|
||||
) => AsyncIterable<TResult> | Promise<AsyncIterable<TResult>>;
|
||||
|
||||
export type SubscriptionResolveFn<TResult, TParent, TContext, TArgs> = (
|
||||
parent: TParent,
|
||||
args: TArgs,
|
||||
context: TContext,
|
||||
info: GraphQLResolveInfo
|
||||
) => TResult | Promise<TResult>;
|
||||
|
||||
export interface SubscriptionSubscriberObject<TResult, TKey extends string, TParent, TContext, TArgs> {
|
||||
subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>;
|
||||
resolve?: SubscriptionResolveFn<TResult, { [key in TKey]: TResult }, TContext, TArgs>;
|
||||
}
|
||||
|
||||
export interface SubscriptionResolverObject<TResult, TParent, TContext, TArgs> {
|
||||
subscribe: SubscriptionSubscribeFn<any, TParent, TContext, TArgs>;
|
||||
resolve: SubscriptionResolveFn<TResult, any, TContext, TArgs>;
|
||||
}
|
||||
|
||||
export type SubscriptionObject<TResult, TKey extends string, TParent, TContext, TArgs> =
|
||||
| SubscriptionSubscriberObject<TResult, TKey, TParent, TContext, TArgs>
|
||||
| SubscriptionResolverObject<TResult, TParent, TContext, TArgs>;
|
||||
|
||||
export type SubscriptionResolver<TResult, TKey extends string, TParent = {}, TContext = {}, TArgs = {}> =
|
||||
| ((...args: any[]) => SubscriptionObject<TResult, TKey, TParent, TContext, TArgs>)
|
||||
| SubscriptionObject<TResult, TKey, TParent, TContext, TArgs>;
|
||||
|
||||
export type TypeResolveFn<TTypes, TParent = {}, TContext = {}> = (
|
||||
parent: TParent,
|
||||
context: TContext,
|
||||
info: GraphQLResolveInfo
|
||||
) => Maybe<TTypes> | Promise<Maybe<TTypes>>;
|
||||
|
||||
export type IsTypeOfResolverFn<T = {}, TContext = {}> = (obj: T, context: TContext, info: GraphQLResolveInfo) => boolean | Promise<boolean>;
|
||||
|
||||
export type NextResolverFn<T> = () => Promise<T>;
|
||||
|
||||
export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs = {}> = (
|
||||
next: NextResolverFn<TResult>,
|
||||
parent: TParent,
|
||||
args: TArgs,
|
||||
context: TContext,
|
||||
info: GraphQLResolveInfo
|
||||
) => TResult | Promise<TResult>;
|
||||
|
||||
|
||||
|
||||
/** Mapping between all available schema types and the resolvers types */
|
||||
export type ResolversTypes = {
|
||||
Boolean: ResolverTypeWrapper<Scalars['Boolean']['output']>;
|
||||
Int: ResolverTypeWrapper<Scalars['Int']['output']>;
|
||||
Mutation: ResolverTypeWrapper<{}>;
|
||||
Query: ResolverTypeWrapper<{}>;
|
||||
String: ResolverTypeWrapper<Scalars['String']['output']>;
|
||||
World: ResolverTypeWrapper<World>;
|
||||
};
|
||||
|
||||
/** Mapping between all available schema types and the resolvers parents */
|
||||
export type ResolversParentTypes = {
|
||||
Boolean: Scalars['Boolean']['output'];
|
||||
Int: Scalars['Int']['output'];
|
||||
Mutation: {};
|
||||
Query: {};
|
||||
String: Scalars['String']['output'];
|
||||
World: World;
|
||||
};
|
||||
|
||||
export type MutationResolvers<ContextType = any, ParentType extends ResolversParentTypes['Mutation'] = ResolversParentTypes['Mutation']> = {
|
||||
setMessage?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType, Partial<MutationSetMessageArgs>>;
|
||||
};
|
||||
|
||||
export type QueryResolvers<ContextType = any, ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query']> = {
|
||||
world?: Resolver<ResolversTypes['World'], ParentType, ContextType>;
|
||||
};
|
||||
|
||||
export type WorldResolvers<ContextType = any, ParentType extends ResolversParentTypes['World'] = ResolversParentTypes['World']> = {
|
||||
x?: Resolver<ResolversTypes['Int'], ParentType, ContextType>;
|
||||
y?: Resolver<ResolversTypes['Int'], ParentType, ContextType>;
|
||||
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
|
||||
};
|
||||
|
||||
export type Resolvers<ContextType = any> = {
|
||||
Mutation?: MutationResolvers<ContextType>;
|
||||
Query?: QueryResolvers<ContextType>;
|
||||
World?: WorldResolvers<ContextType>;
|
||||
};
|
||||
|
||||
@@ -1,25 +1,11 @@
|
||||
import { createModule, gql } from "graphql-modules";
|
||||
import { createModule } from "graphql-modules";
|
||||
import { loadFilesSync } from "@graphql-tools/load-files";
|
||||
import { resolvers } from "./resolvers";
|
||||
import { join } from "node:path";
|
||||
|
||||
export const exampleModule = createModule({
|
||||
id: "example-module",
|
||||
dirname: __dirname,
|
||||
typeDefs: [
|
||||
gql`
|
||||
type Query {
|
||||
hello: String!
|
||||
world: World!
|
||||
}
|
||||
|
||||
type World {
|
||||
x: Int!
|
||||
y: Int!
|
||||
}
|
||||
`,
|
||||
],
|
||||
resolvers: {
|
||||
Query: {
|
||||
hello: () => "world",
|
||||
world: () => ({ x: 1, y: 2 }),
|
||||
},
|
||||
},
|
||||
typeDefs: loadFilesSync(join(__dirname, "./typedefs/*.graphql")),
|
||||
resolvers,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/* eslint-disable */
|
||||
import * as Types from "../../gql/graphql";
|
||||
import * as gm from "graphql-modules";
|
||||
export namespace ExampleModule {
|
||||
interface DefinedFields {
|
||||
Query: 'world';
|
||||
Mutation: 'setMessage';
|
||||
World: 'x' | 'y';
|
||||
};
|
||||
|
||||
export type Query = Pick<Types.Query, DefinedFields['Query']>;
|
||||
export type World = Pick<Types.World, DefinedFields['World']>;
|
||||
export type Mutation = Pick<Types.Mutation, DefinedFields['Mutation']>;
|
||||
|
||||
export type QueryResolvers = Pick<Types.QueryResolvers, DefinedFields['Query']>;
|
||||
export type MutationResolvers = Pick<Types.MutationResolvers, DefinedFields['Mutation']>;
|
||||
export type WorldResolvers = Pick<Types.WorldResolvers, DefinedFields['World'] | '__isTypeOf'>;
|
||||
|
||||
export interface Resolvers {
|
||||
Query?: QueryResolvers;
|
||||
Mutation?: MutationResolvers;
|
||||
World?: WorldResolvers;
|
||||
};
|
||||
|
||||
export interface MiddlewareMap {
|
||||
'*'?: {
|
||||
'*'?: gm.Middleware[];
|
||||
};
|
||||
Query?: {
|
||||
'*'?: gm.Middleware[];
|
||||
world?: gm.Middleware[];
|
||||
};
|
||||
Mutation?: {
|
||||
'*'?: gm.Middleware[];
|
||||
setMessage?: gm.Middleware[];
|
||||
};
|
||||
World?: {
|
||||
'*'?: gm.Middleware[];
|
||||
x?: gm.Middleware[];
|
||||
y?: gm.Middleware[];
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { ExampleModule } from "./module-types";
|
||||
|
||||
export const resolvers: ExampleModule.Resolvers = {
|
||||
Query: {
|
||||
world: async () => {
|
||||
return { x: 1, y: 2 };
|
||||
},
|
||||
},
|
||||
Mutation: {
|
||||
setMessage: async (_, { message }) => {
|
||||
return `Set message to: ${message}`;
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
type Query {
|
||||
world: World!
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
setMessage(message: String): String
|
||||
}
|
||||
|
||||
type World {
|
||||
x: Int!
|
||||
y: Int!
|
||||
}
|
||||
Reference in New Issue
Block a user