- 324f084: Support graphql@17
- Updated dependencies [324f084]
- @eddeee888/gcg-server-config@0.5.0
- b49fb8a: Drop Node 20 support
- b49fb8a: Bump codegen packages
- Updated dependencies [b49fb8a]
- Updated dependencies [b49fb8a]
- @eddeee888/gcg-server-config@0.4.0
- eb89da1: Sync/bump Codegen package versions to avoid type issues
- Updated dependencies [eb89da1]
- @eddeee888/gcg-server-config@0.3.1
- a5de01f: add importExtension configuration option
- 1591c8d: Add moduleNamingMode option
-
e0476b3: Add fixObjectTypeResolvers
fastmode (experimental)This is now the default static analysis mode. If you see behaviour or runtime issues, please set
fixObjectTypeResolvers: smartand file a report at https://github.com/eddeee888/graphql-code-generator-plugins/issues
- f14a549: Bump codegen packages major version
- Updated dependencies [f14a549]
- @eddeee888/gcg-server-config@0.3.0
- 6d79fc2: Fix issue where shorthand assignment are not detected for static analysis
-
7f03d24: Avoid low-level TypeScript typechecker usage unncessarily, which breaks when running static analysis
Originally,
getTypefunction was called during static analysis to get low-levelTypefor each type property declarations. These types can be used in typechecker'sisAssignableTofunction, which would have a significant perf boost (if done right). However, there needs to be a significant change to use.isAssignableTo, sogetTypewas left there so we can continue the work later.However, declarations of a node could be
undefinedif the type is wrapped in generics that synthesies properties(?). This causes the runtime error. Relevant convoFor now, we can just remove the
getTypecall, until we know how to handle these typing issues.
-
e84fb01: Add mappersRelativeTargetDir config option
string(Default:./)By default, mappers must be siblings with the schema they represent. For example, if the schema file is
/path/to/schema.graphql, the mapper file is/path/to/schema.mappers.ts. This extension allows mappers to reside in a different directory relative to the schema file using the pattern<schemaPath>/<mappersRelativeTargetDir>/<schemaName><mappersFileExtension>. -
221c671: Add moduleNamingMode option to determine the module name for each schema file
last: The module name is derived from the last directory (within the schema directory) in the file's path.first: The module name is derived from the first directory (within the schema directory) in the file's path.- any number: The module name is derived from the nth zero-indexed directory (within the schema directory) in the file's path. Supports negative numbers which select the nth directory from the back of the file's path.
- 19e1f03: Fix __resolveReference being required all the time
- b4c501c: Update internals to use faster approach to run static analysis
- df77f2e: Fix issue generated type names with custom naming convention breaks mappers static analysis
- Updated dependencies [19e1f03]
- @eddeee888/gcg-server-config@0.2.3
- 9b45bf3: Use @graphql-codegen/typescript-resolvers meta to handle federation__resolveType
- 9b45bf3: Do not add files on filesystem that have not been touched by codemod
- 9b45bf3: Do not report namingConvention usage as it is fully supported
- 7f281c9: Fix scalarOverrides not giving full control to users
- de78270: Ensure __isTypeOf is in the picked properties so users can choose this way to handle abstract type should they choose
- 9088222: Fix interface mappers not being detected automatically
- 906d454: Bump @graphql-codegen/typescript-resolvers to v4.2.1
- bb9b5fe: Use @graphql-tools/merge to merge typeDefs
- Updated dependencies [906d454]
- @eddeee888/gcg-server-config@0.2.2
- 8ec553b: Handle enum resolverGeneration, autowireup and mapper. Enable enum resolvers generation by default.
- 8ec553b: Use reported generated type names from @graphql-codegen/typescript-resolvers meta to support all naming convention
- 8ec553b: Add
fixObjectTypeResolvers.enum = smartoption to ensure all allowedValues are generated - 8ec553b: Fully support namingConvention for resolvers map
- b734d8b: Revert VariableStatement assumption that can cause runtime errors
- 386bb30: Fix issue where variable statements without type node does not get type node added
- 6715a49: Prefer detected scalar file on filesystem over scalar modules when wiring up resolvers map
- 86babc6: Fix issue where GraphQLScalarType is imported all the time, regardless of whether it's used
- 538eb24: Fix issue where whitelisted/blacklisted module can incorrectly detect extended resolvers to wire up to resolvers.generated.ts
- 263604f: Fix externalResolvers config not working for enums
- e999093: Add hooks to defineConfig context
-
454d1df: Add resolverGeneration 'minimal' mode
minimalis the equivalent of:{ "query": "*", "mutation": "*", "subscription": "*", "scalar": "*", "object": "", "union": "", "interface": "" } -
454d1df: Implement file auto-wireup if detected at the right filesystem location
- c48e8c6: Update internals to avoid parsing schema twice
- 3213b73: Bump base codegen plugin to apply patches from upstream
- d6df63c: Force generate object types with mappers to avoid runtime errors
- Updated dependencies [3213b73]
- @eddeee888/gcg-server-config@0.2.1
-
6bf957d: Extend
resolverGenerationfunctionalityAllow passing in an object that to control which files to be generated. By default (i.e.
resolverGeneration: 'recommended'), it's equivalent to the following settings:defineConfig({ resolverGeneration: { query: '*', mutation: '*', subscription: '*', scalar: '*', object: '*', union: '', interface: '', }, });
Each option can take a glob pattern to tell the preset which files of a given type to be generated based on its normalized file name.
A normalized file name has this pattern:
<Module name>.<Top-level type name>.<Field resolver>?Consider this schema:
# src/schema/pet/schema.graphql extend type Query { pets: [Pet!]! } type Cat { id: ID! } type Dog { id: ID! } union Pet = Cat | Dog # src/schema/user/schema.graphql extend type Mutation { createUser(id: ID!): CreateUserResult! } type User { id: ID! } type CreateUserOk { result: User! } type CreateUserError { error: String! } union CreateUserResult = CreateUserOk | CreateUserError
Then, the generated files and normalised names are:
src/schema/pet/resolvers/Query/pets.ts, affected byqueryoption, normalized name:pet.Query.petssrc/schema/pet/resolvers/Cat.ts, affected byobjectoption, normalized name:pet.Catsrc/schema/pet/resolvers/Dog.ts, affected byobjectoption, normalized name:pet.Dogsrc/schema/pet/resolvers/Pet.ts, affected byunionoption, normalized name:pet.Petsrc/schema/user/resolvers/Mutation/createUser.ts, affected bymutationoption, normalized name:user.Mutation.createUsersrc/schema/user/resolvers/User.ts, affected byobjectoption, normalized name:user.Usersrc/schema/user/resolvers/CreateUserOk.ts, affected byobjectoption, normalized name:user.CreateUserOksrc/schema/user/resolvers/CreateUserError.ts, affected byobjectoption, normalized name:user.CreateUserErrorsrc/schema/user/resolvers/CreateUserResult.ts, affected byunionoption, normalized name:user.CreateUserResult
Now, let's say we want to disable all union files, types ending with
OkorError, the config would look like this:defineConfig({ resolverGeneration: { query: '*', mutation: '*', subscription: '*', scalar: '*', object: ['!*.*Ok', '!*.*Error'], // Disables objects ending with `Ok` or `Error` in every module union: '', // Empty string disables all file generation of relevant type in every module interface: '*', }, });
-
00a80bc: Bump ts-morph to v22 which requires TypeScript 5.4
-
6bf957d: Add colours to logs
-
de5599b: Move union and interface config from server config to server preset
This config is fairly opinionated and may not make sense being on server config. However, it is definitely the default mode of operation we want to use for server preset to avoid having extra files, simplifying the setup.
-
Updated dependencies [de5599b]
- @eddeee888/gcg-server-config@0.2.0
-
4ab8016: Use TypeScript typechecker to collect type properties
Previously, we manually walked through the program to collect properties of types. This is problematic as there are lots of ways to declare mappers that we cannot manually handle. On top of this, type property properties can be handled natively correctly by TypeScript typechecker.
Note: class declaration private properties are picked up by TypeScript typechecker, which could be problematic. We are keeping that case as-is.
- e909a17: fix path to output resolver files in main resolver files for nested schema files
- 067bd7e: Add params to generated resolvers
- 47c8fa6: Update package.json with missing deps
- 891f718: fix path to output resolver files so they are always generated near to schema.graphql
- b226761: Implement recursively pick interface extensions
- Updated dependencies [47c8fa6]
- @eddeee888/gcg-server-config@0.1.1
- 9f3b82b: Federation support: Add __resolveReference to picked fields when extending object types
- 8ed14fc: Fix issue where dashes were not handled correctly when using extended object pattern across multiple schemas
- 7567190: Declare tslib as a dependency
-
73d9936: Relax
presetConfig.typesPluginsConfig.namingConventionenforcement. Warn if used.In v0.7.0, we've made
presetConfig.typesPluginsConfig.namingConventionto throw if used. In this release, we've relaxed it because certain options may still work e.g.upperCaseFirst. IfnamingConventionis used, we warn instead.Currently, the preset naively uses the schema type spelling/casing as the generated type. Therefore, it's important to have
namingConventionoption askeep. In the future, we can revisit to make sure generated resolvers have the samenamingConventionsupport as the generated type file.
-
ab6a9e7: Support extending non-root object types
For example, given this schema:
# user/schema.graphql type User { id: ID! } # car/schema.graphql extend type User { cars: [Car!]! } # house/schema.graphql extend type User { housesOwned: [House!]! housesSold: [House!]! }
It'd generate these files:
// user/resolvers/User.ts export const User: Pick<UserResolvers, 'id'> = { // ... }; // car/resolvers/User.ts export const User: Pick<UserResolvers, 'cars'> = { // ... }; // house/resolvers/User.ts export const User: Pick<UserResolvers, 'housesOwned' | 'housesSold'> = { // ... };
And the main resolver file:
// resolvers.generated.ts import { User as user_User } from './user/resolvers/User'; import { User as car_User } from './car/resolvers/User'; import { User as house_User } from './house/resolvers/User'; export const resolvers: Resolvers = { User: { ...user_User, ...car_User, ...house_User, }, };
-
d5d9577: Drop support for
typesPluginsConfig.namingConvention- this is now alwayskeepIn the preset, we made the assumption that the types used in resolver files are in the same format as the schema. So we
keepthe naming convention.Some types in
types.generated.tsare affected. However, they are not currently used in any of the resolver files. So, if consumers have leaned into the recommended default config and generated resolver files (which is the intention of the preset), then there should be no issue upgrading. -
5497e8f: Add experimental support for add plugin.
Consumers can use the preset's
addoption to do the equivalent of theaddplugin to target the generated resolvers type file (defaulttypes.generated.ts).Example:
// codegen.ts { generates: { 'src/schema': defineConfig({ add: { './types.generated.ts': { content: '/* eslint-disable */' }, }, }) } }
- Updated dependencies [ccdc5e2]
- @eddeee888/gcg-server-config@0.1.0
-
d0e17ad: Add resolverGeneration option
disabledorrecommendedorall(Default:recommended)Decides which resolvers to generate:
disabled: generates no resolvers. Use this if you want to use your own structures. Note: if custom scalars are detected and used, resolver main files are still generated.recommended: generates the minimal amount of resolvers. Use this if you want a managed experience.- no union/interface resolvers are generated because we rely on certain settings in
typescript-resolversthat make these not required.
- no union/interface resolvers are generated because we rely on certain settings in
all: generates all resolvers. Use this if you want all resolvers to be generated and use the ones you need.
-
1586d73: Add missing Interface file generation
-
c3ee642: Fix emitLegacyCommonJSImports issues
- Fix issue where warning always logged if
presetConfig.emitLegacyCommonJSImportsis used - Throw error when
presetConfig.typesPluginsConfig.emitLegacyCommonJSImportsis used - (Internal) Replace automatic file detection in
printImportLinewith 3 options:file,moduleandpreserve:- This is to fix rare cases where absolute alias path is used in
externalResolversoption e.g.src/module/filewas missing.jsbecause it was being detected as a module.externalResolversis set by the user and also used internally for scalar types, so we can usepreserveinstead to keep the module value as-is. - Options:
file: import is a file. For ESM, .js extension is added. For CJS, no extension is added.module: import is a module fromnode_modulesor aliased e.g.graphql-scalarsor@org/your-module. No extension is added.preserve: preserve what the config declares. This is only used when taking user's config or preset-controlled config e.g.externalExternalsbecause the import could be either file or module
- This is to fix rare cases where absolute alias path is used in
- Fix issue where warning always logged if
-
191705f: Add schema option to defineConfig
-
49ba468: Added support for the case where the Type mapper is a class
-
c968c2c: Fix: defineConfig's type no longer allows typesPluginsConfig.scalars or typesPluginsConfig.emitLegacyCommonJSImports
-
2205e3f: Update default custom GraphQLScalar template to guide users better
-
Updated dependencies [5e58a08]
- @eddeee888/gcg-server-config@0.0.1
-
f7831c1: Use resolversNonOptionalTypename instead of nonOptionalTypename
This makes using abstract types simpler because we do not return __typename for all types, only for union members and interface implementing types.
-
f7831c1: Add scalarsOverrides config option
Record<string, { resolver?: string; type?: string | { input: string; output: string } }>(Default:{})Overrides scalars' resolver implementation, type or both.
Example:
// codegen.ts { generates: { 'src/schema': defineConfig({ scalarsOverrides: { DateTime: { resolver: './localDateTimeResolver#Resolver', } Currency: { type: 'unknown' }, BigInt: { resolver: '@other/scalars#BigIntResolver', type: 'bigint' } } }) } }
BREAKING CHANGE:
typesPluginsConfig.scalarscan no longer be used. Please usescalarOverridesinstead. -
f7831c1: Use optionalResolveType=true because resolversNonOptionalTypename works
-
f7831c1: Add scalarsModule config option
stringorfalse(Default:graphql-scalars)Where Scalar implementation and codegen types come from. Use
falseto implement your own Scalars.If using an module that is not
graphql-scalars, the module must export resolver implementation and codegen type the same waygraphql-scalarsdoes e.g.{ resolvers: { DateTime: DateTimeResolver, }, DateTimeResolver: { // ... resolver implementation extensions: { codegenScalarType: 'Date | string', }, } }
- f7831c1: Allows overriding native scalar types' type (Equivalent of typescript plugin's scalars option)
- f7831c1: Correctly implement ID Scalar's input/output type: input is string and output is string | number
- af10b65: Add emitLegacyCommonJSImports config option to support esm-style imports in generated output
- 72c0dc1: Fix typeDefsFileMode=modules not working well with codegen hooks (e.g. afterAllFileWrite) for Windows
-
037afdc: Add resolverMainFileMode.
mergedormodules(Default:merged)How to generate file/s that put resolvers map together:
merged: one filemodules: one file per module. This can be used with module-based libraries like graphql-modules
Example codegen config:
// codegen.ts import type { CodegenConfig } from '@graphql-codegen/cli'; import { defineConfig } from '@eddeee888/gcg-typescript-resolver-files'; const config: CodegenConfig = { schema: '**/*.graphql', generates: { 'src/schema': defineConfig({ resolverMainFileMode: 'modules', }), }, }; export default config;
resolverMainFileMode=modulesgenerates oneresolvers.generated.tsfile in each module:├── src/ │ ├── schema/ │ │ ├── base/ │ │ │ ├── schema.graphql │ │ │ ├── resolvers.generated.ts # contains resolvers of types in `src/schema/base/schema.graphql` │ │ ├── user/ │ │ │ ├── schema.graphql │ │ │ ├── resolvers.generated.ts # contains resolvers of types in `src/schema/user/schema.graphql` │ │ ├── book/ │ │ │ ├── schema.graphql │ │ │ ├── resolvers.generated.ts # contains resolvers of types in `src/schema/book/schema.graphql`If you are using
graphql-modules, you can use the resolvers map like this:// src/schema/user/index.ts import { createModule } from 'graphql-modules'; import { resolvers } from './resolvers.generated.ts'; export const userModule = createModule({ id: 'user-module', dirname: __dirname, typeDefs: [ /* Your typeDefs*/ ], resolvers, });
-
df06e3b: Add typeDefsFileMode.
mergedormergedWhitelistedormodules(Default:merged)How to generate typeDefs file/s:
merged: one filemergedWhitelisted: one file but only contains whitelisted modules. This is useful if your blacklisted modules handle their own type defsmodules: one file per module. This can be used with module-based libraries like graphql-modules
Example codegen config:
// codegen.ts import type { CodegenConfig } from '@graphql-codegen/cli'; import { defineConfig } from '@eddeee888/gcg-typescript-resolver-files'; const config: CodegenConfig = { schema: '**/*.graphql', generates: { 'src/schema': defineConfig({ typeDefsFileMode: 'modules', }), }, }; export default config;
typeDefsFileMode=modulesgenerates onetypeDefs.generated.tsfile in each module:├── src/ │ ├── schema/ │ │ ├── base/ │ │ │ ├── schema.graphql │ │ │ ├── typeDefs.generated.ts # contains typeDefs of `src/schema/base/schema.graphql` │ │ ├── user/ │ │ │ ├── schema.graphql │ │ │ ├── typeDefs.generated.ts # contains typeDefs of `src/schema/user/schema.graphql` │ │ ├── book/ │ │ │ ├── schema.graphql │ │ │ ├── typeDefs.generated.ts # contains typeDefs of `src/schema/book/schema.graphql`If you are using
graphql-modules, you can use the resolvers map like this:// src/schema/user/index.ts import { createModule } from 'graphql-modules'; import { typeDefs } from './typeDefs.generated.ts'; export const userModule = createModule({ id: 'user-module', dirname: __dirname, typeDefs: [typeDefs], resolvers: { /* Your resolver map */ }, });
-
086802e: Add
defineConfig. This sets uppreset,presetConfigandwatchPattern.Example:
import type { CodegenConfig } from '@graphql-codegen/cli'; import { defineConfig } from '@eddeee888/typescript-resolver-files'; const config: CodegenConfig = { schema: 'src/schema/**/*.graphql', generates: { 'src/schema': defineConfig(), }, }; export default config;
- fe0ca5d: Bump ts-morph to v18
- d5aac16: Handle intersection typeNode usually seen in GQL Interface types e.g.
type TypeA = TypeB & { something: string } & { somethingelse: string } - 6324453: Fix Subscription default generation template
- b70ee7f: Use path.posix to fix Windows errors
- 5302e38: Add example for custom preset config in README
- 686cafd: Implement type comparison between mapper type vs schema type to generate resolvers
- 75fc48b: Bump @graphql-codegen/* deps
- 0d3c9db: Generate typeDefs by default
- 0a07d09: Make graphql-scalars deps because it is used in implementation
- 120a06a: Make resolverRelativeTargetDir more reasonable for merged mode
- 80986d8: Update config setting names and defaults to prioritise 'modules' mode over 'merged'
- 6a918ed: Fix deps vs peerDeps in package.json
- a81f7f3: Implement auto mappers
- 9646937: Fix Scalars in blacklisted modules not being ignored correctly
- a53b315: Make generated RootObjectTypeFields NonNullable to make reexports easier
- eda27b7: Add blacklistedModules config
- a15db13: Merge internal
typescriptandtypescript-resolversplugins config to onetypesPluginsConfigfield
- bcfe20d: Use graphql-scalars types and config
- bcfe20d: Add support with overrides for typescript and typescript-resolvers plugins
- 5065768: Turn to preset to better integrate with codegen
- 0a99233: Implement generating logic for Scalar type
- b2fe4da: Implement config.externalResolvers
- 49ffe7a: Initial publish