OpenAPITools / OpenAPITools/openapi-generator

[BUG] [graphql-schema] Generator not generating correct types for Queries and mutations

Open
#14,391 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

The schema generator does not work properly.

I used the following command to generate a graphQL-schema for the petstore:

openapi-generator generate -i petstore.yaml -g graphql-schema

The resulting generated schema is not compiling since the mutations and queries are generated like so

type query {
  # Get user by user name
  # 
  # @param String! username The name that needs to be fetched. Use user1 for testing. 
  # @return [User]
  GetUserByName(username: String!): User

  # Logs user into the system
  # 
  # @param String! username The user name for login
  # @param String! password The password for login in clear text
  # @return [String!]
  LoginUser(username: String!, password: String!): String!

  # Logs out current logged in user session
  # 
  # @return [null]
  LogoutUser(): null

} 

Yet a type has to start with a capital letter. Additionally the problem is that the input types, e. g. User in CreateUser are not declared to be an input and thus cannot be used as a parameter for Queries or Mutations.

openapi-generator version

6.2.1

Generation Details

openapi-generator generate -i petstore.yaml -g graphql-schema

Steps to reproduce

Download the petstore yaml.
Execute the following command: openapi-generator generate -i petstore.yaml -g graphql-schema

Suggestions for fix

This probably means that the Queries and Mutations cannot be split in separate files due to resulting name conflicts.
Additionally the types might need to be generated two times once as type and once as input.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the documented openapi-generator command with the petstore YAML and inspect the generated GraphQL schema. Check the query and mutation declarations and how model types are used as inputs. Done means the generated schema compiles, uses valid Query and Mutation types, and declares compatible input types for mutation parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.