Describe the bug
Query and QueryResolvers only generate the types for type Query. extend type Query seem to be ignored.
This worked in 1.7.0, but has stopped working in 1.8.0.
To Reproduce
Steps to reproduce the behavior:
# Put your schema here
type Query {
foo: String
}
extend type Query {
bar: String
}
Will generate:
export type Query = {
__typename?: 'Query',
foo?: Maybe<Scalars['String']>,
};
export type QueryResolvers<ContextType = any, ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query']> = {
foo?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>,
};
However,
# Put your schema here
type Query {
foo: String
bar: String
}
Will generate:
export type Query = {
__typename?: 'Query',
foo?: Maybe<Scalars['String']>,
bar?: Maybe<Scalars['String']>,
};
export type QueryResolvers<ContextType = any, ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query']> = {
foo?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>,
bar?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>,
};
# Put your operations here
codegen.yml config file:schema: ./src/schema.tsx
generates:
./src/resolvers.types.tsx:
config:
avoidOptionals: false
noSchemaStitching: true
enumsAsTypes: true
plugins:
- typescript
- typescript-resolvers
require:
- ../../../../../util/register.js
Expected behavior
Expect extend type Query to merge with type Query and generate types properly.
Environment:
10.14.6@graphql-codegen/^1.8.0: 10.16.0Additional context
Here is my schema.tsx file.
import {makeExecutableSchema} from 'graphql-tools';
const schema = makeExecutableSchema({
typeDefs: [`
type Query {
foo: String
}
extend type Query {
bar: String
}
`],
resolvers: [鈥,
});
@chemoish it seems like your are importing your schema from a code file, can you share the exact content of it?
@dotansimha Sorry, I am new to this. I have attached the schema file in the Additional context.
This might be related to graphql-toolkit and they way it loads schemas from code files.
@kamilkisiela @ardatan what do you think?
That's because printed schema doesn't include extensions. The extendSchema function has to be used on a built schema but it requires to extract extensions into a new DocumentNode and apply that instead. I noticed the same issue in Inspector yesterday. I'll fix it on Monday.
@dotansimha
Same problem here! I'm pretty sure that the bug was introduced after version 1.3.1. I have a working project with version 1.3.1 and a new project created some days ago with problem! I tried to understand what is the first version affected without lucky!
@kamilkisiela Thanks for taking a look at this! Any idea when this might make the release cycle?
Any news about that bug?
@kamilkisiela has some experiments, the only workaround we can suggest at the moment is to load the schemas as SDL, and not using code file. When we load a compiled GraphQLSchema is causes the AST nodes extensions to be unavailable.
@chemoish I encounter the same problem, how did you fix it?
@ChrisLahaye I don't use extend so that is my work around.
@chemoish How do you split your Query and Mutation over multiple files?
@ChrisLahaye Just put your schema SDL definitions in multiple .graphql files, and use glob expression to tell the codegen where to find it (./**/*.graphql).
@dotansimha but in that case I will need to define my Query and Mutation type in a single file, unless I use extend?
@chemoish @ChrisLahaye We changed the behavior of schema loaders and mergers against schema extensions. This should be fixed for you.
Could you check this version?
1.10.1-alpha-7abaacf0.6
Fixed in 1.11.0
Most helpful comment
That's because printed schema doesn't include extensions. The
extendSchemafunction has to be used on a built schema but it requires to extract extensions into a new DocumentNode and apply that instead. I noticed the same issue in Inspector yesterday. I'll fix it on Monday.@dotansimha