Generating schema.json

378 views
Skip to first unread message

Shankar Raman

unread,
Mar 21, 2016, 1:43:19 PM3/21/16
to graphql-java
I am not sure how to generate the "schema.json" that's used by Relay, I have seen the following syntax
 graphql(schema, introspectionQuery)
however how do I access the schema that's generated on the server side? I can see how to do it on the client side. 
Any help would be appreciated. 
Thanks.

andimarek

unread,
Apr 3, 2016, 10:51:23 PM4/3/16
to graphql-java
Hi,

you need a running a server and then execute a introspection query against it.

The result is the schema.json.

You could do that for example with a curl command: 

curl -vvv -X POST -H 'Accept: application/json' -H 'Content-type: application/json' -d @introspection-query.txt -o data/schema.json <URL-OF-YOUR-ENDPOINT>

The query must be in the introspection-query.txt file and the output will be written into data/schema.json.

Raphael Hsieh

unread,
Feb 23, 2017, 6:51:10 PM2/23/17
to graphql-java
Is there any way to run the introspection query without running the server? 
I'm trying to generate the schema.json in my systems build step.

Thanks

trb...@gmail.com

unread,
Mar 3, 2017, 9:26:53 PM3/3/17
to graphql-java
Hi Raphael,
I was attempting to build the schema.json at build time as well, I was able to accomplish this very easily:
     public static void main(String[] args) throws IOException, URISyntaxException {
        GraphQLServlet servlet = new GraphQLServlet();
        querys.stream()
                .forEach(query -> servlet.bindQueryProvider(query));
        mutations.stream()
                .forEach(mute -> servlet.bindMutationProvider(mute));

        String schemaResult = servlet.executeQuery(INTROSPECTION_QUERY);
        Files.write(Paths.get(System.getProperty("target.path"), "schema.json"),
                schemaResult.getBytes());
    }

Hope this helps!
Reply all
Reply to author
Forward
0 new messages