question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Generate GraphQL schema with just Types?

See original GitHub issue

Hello,

Is it possible to generate a simple schema based on a Java POJO without including any queries/mutations via GraphQLSchemaGenerator?

I tried the following:

@GraphQLType
public class TestPojo
{

    private String test;

    public String getTest()
    {
        return test;
    }
}

and Schema generation code snippet:

return new GraphQLSchemaGenerator()
                .withBasePackages( "com.xyz" )
                .withOperationsFromTypes( TestPojo.class )
                .generate();

Is there any way to accomplish something like this? When I create a simple TestQuery class and include the TestPojo object as a return type which is annotated with @GraphQLQuery, I get the TestPojo type along with the query as expected. I simply would like to build a schema where there are no queries but only types. Is this possible?

Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kaqqaocommented, Feb 8, 2021

I see. I think the approach above gets you almost as close as possible to a types-only schema without violating the spec. I could theoretically make a method that removes the need for an explicit dummy, but it’s very dubious if that would make sense in the lib. That said, I’ll close this issue, but feel free to reopen if you’d like it addressed differently.

0reactions
mrFatDZcommented, Feb 8, 2021

We have a legacy JMS Java API that we want to expose existing POJOs from as GraphQL types to our new frontend. Our frontend application connects to the same legacy application via parallel WS and we pipe the messages to the same JMS broker. We wanted our application to download the schema files containing GQL Types from JMS POJOs and uses them at the application layer. This way we can control both APIs from the same source.

I know this isn’t the most ideal design but it “gets us by” until we migrate everything over to GQL Queries/Mutations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generated GraphQL Schemas and Schema Design
A GraphQL schema is a machine and human-readable document that declares what operations are available and what types those operations return.
Read more >
Schemas and Types - GraphQL
The most basic components of a GraphQL schema are object types, which just represent a kind of object you can fetch from your...
Read more >
Generating TypeScript Types for GraphQL Schema ... - YouTube
In this video I'll show how to generate TypeScript types for GraphQL schema, resolvers, queries and mutations using GraphQL Code Generator.
Read more >
Generating TypeScript Types from GraphQL Schema in Apollo
In this video we'll see how to generate TypeScript types automatically from our GraphQL queries using Apollo.
Read more >
Generate GraphQL schema from TypeScript? - Stack Overflow
type -graphql only works if all custom types are class es. That doesn't work for me; I don't have a single class but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found