dotansimha / dotansimha/graphql-code-generator

[typescript-resolvers] Missings args types in QueryResolvers

Open
#5,968 2 comments 0 reactions 0 assignees View on GitHub
core stage/0-issue-prerequisites
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

**Describe the bug**

Args (my case `limit`) are not generated on `QueryResolvers["landing"]`

They are generated on `LandingResolvers` tho

The query works in runtime of course

**To Reproduce**
Steps to reproduce the behavior:

1. My GraphQL schema:

```graphql
type City implements Node {
id: ID!
isFeatured: Boolean!
name: String!
}

type Query {
landing: Landing
}

type Landing {
# This is generated for LandingResolvers, but not for QueryResolvers["landing"]
featuredCities(limit: Int!): [City!]!
}

```

2. My GraphQL operations:

```graphql
query {
landing {
featuredCities(limit: 2) {
code
}
}
}
```

3. My `codegen.yml` config file:

```yml
schema: http://localhost:8081/graphql

config:
noSchemaStitching: true
optionalInfoArgument: true
federation: false
useTypeImports: true
# useIndexSignature: true
maybeValue: T | null | undefined
contextType: ./ApolloContext#ApolloContext
# also check web repo codegen.yml for scalars
scalars:
DateTime: string
Date: string
Time24H: string
Money: string
mappers:
City: ./GeneratedDb#City as CityDb

generates:
src/types/GeneratedGql.ts:
plugins:
- typescript
- typescript-resolvers

```

4. Generated types:

```ts
export type QueryResolvers = ResolversObject<{
landing?: Resolver, ParentType, ContextType>;
}>;

/** Mapping between all available schema types and the resolvers types */
export type ResolversTypes = ResolversObject<{
Landing: ResolverTypeWrapper & { featuredCities: Array }>;
}>;

/**
* Here the args are missing
*/
export type LandingResolvers = ResolversObject<{
featuredCities?: Resolver, ParentType, ContextType, RequireFields>;
}>;
```

```ts
export const query: QueryResolvers["landing"] = () => ({
/**
* Here limit is any / untyped
*/
featuredCities: ({ limit }) =>
getCityBase().where({ isFeatured: true }).limit(makeLimit(limit)).orderBy("name", "asc"),
```

**Expected behavior**

**Environment:**

- OS: macOS 11.2
- `@graphql-codegen/...`:
- ├─ @graphql-codegen/cli@1.21.4
├─ @graphql-codegen/core@1.17.9
├─ @graphql-codegen/plugin-helpers@1.18.5
├─ @graphql-codegen/typescript-resolvers@1.19.1
├─ @graphql-codegen/typescript@1.22.0
├─ @graphql-codegen/visitor-plugin-common@1.20.0
- NodeJS: 14
- TS: typescript@4.2.4

**Additional context**

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.