Skip to content

Generate client code from introspection query response #165

@lmartellotto

Description

@lmartellotto

Is your feature request related to a problem? Please describe.
Always same context: we use this project to test our GraphQL API with RestAssured. We use your maven plugin for generating client code from schema file, before compiling and running RestAssured tests.

From our pom.xml for example:

          <!-- Generate GraphQL client classes from schema. -->
          <plugin>
            <groupId>io.github.kobylynskyi</groupId>
            <artifactId>graphql-codegen-maven-plugin</artifactId>
            <version>1.8.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <graphqlSchemaPaths>${project.basedir}/src/integration-test/resources/schema.graphqls</graphqlSchemaPaths>
                        <outputDir>${project.build.directory}/generated-test-sources/graphql</outputDir>
                        ...

It works great!
But we have to write these schema file(s) that we use to generate this code client.

Describe the solution you'd like
Can we imagine:

  1. the maven plugin does a HTTP request to the GraphQL API sending an introspection query.
  2. the graphql-java-codegen lib is able to generate the client code from this introspection query response (instead of only GQL schema).

Of course, this will be an additionnal feature to the plugin. The plugin must always support the generation from schema file.

I think it will be relevant, specially for generating client code in order to really use the GraphQL API (and not only for testing). Because, server and client aren't probably in the same project. For example, it can be done with Swagger in command line: https://github.com/swagger-api/swagger-codegen#to-generate-a-sample-client-library

However, I don't know if it is easily possible, because the result of introspection query has absolutely not the same format of the schema file.

Before thinking about details, I want to know if you think that it is relevant and possible ?

Describe alternatives you've considered
The first step (retrieving introspection query response from API) maybe can be done by another maven plugin in order to simplify the feature. For example: https://github.com/cjnygard/rest-maven-plugin (I don't take time to test this plugin, but I'm almost sure we can find a maven plugin which makes the job).

Thanks for your time,
Laura

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions