graphql-java

GraphQL java send custom error in json format

核能气质少年 提交于 2019-12-05 20:13:45
I am working in an graphql application where I have to send custom error object / message in json irrespective of whether it occurs in servlet or service. Expected error response { errorCode: 400 //error goes here, errorMessage: "my error mesage"} It will be helpful if someone could guide me to achieve the above requirement. felipe_gdr GraphQL specification defines a clear format for the error entry in the response. According to the spec, it should like this (assuming JSON format is used): "errors": [ { "message": "Name for character with ID 1002 could not be fetched.", "locations": [ { "line"

Should I write two times each objects as 'input' and 'type' in a graphql schema file

一世执手 提交于 2019-12-05 18:08:35
I have to use a Java object in GraphQL in response as well as in request. Should I have to write two times each objects as 'input' and 'type' in a GraphQL schema file? For getting that object in request as well as in response. Should I define the same object two times with input and type? file: test.graphqls input Employee{ id:Integer name:String dept:String active:String } type Employee{ id:Integer name:String dept:String active:String } Yes, because the type system rules are very different for input and output types. Input types can not be unions, can not implement interfaces etc, so you can

Inject bean into DataFetcher of GraphQL

。_饼干妹妹 提交于 2019-12-05 11:43:26
I'm using Spring & graphql-java ( graphql-java-annotation ) in my project. For retrieving data part, i'm using a DataFetcher to get data from a service (from database). The weird thing is that: myService is always null . Anyone know the reason? DataFetcher @Component public class MyDataFetcher implements DataFetcher { // get data from database @Autowired private MyService myService; @Override public Object get(DataFetchingEnvironment environment) { return myService.getData(); } } Schema @Component @GraphQLName("Query") public class MyGraphSchema { @GraphQLField @GraphQLDataFetcher

authentication in spring boot using graphql

主宰稳场 提交于 2019-12-03 02:52:25
I’m working on a spring boot project with GraphQL. I'm using graphql-java-tools and graphql-spring-boot-starter. I managed to configure security and session management with spring security as you can see in the java config files below. Now the “/graphql” path is secured (it can be accessed only sending the “basic http authentication” or a session token ( x-auth-token ) in a http header of the request). Authenticating with “basic http authentication” on any GraphQL operation will start a new session and send back the new session token in a header, and that token can be used further to continue

graphql-java - How to use subscriptions with spring boot?

天大地大妈咪最大 提交于 2019-12-03 00:36:02
In a project I use graphql-java and spring boot with a postgreSQL Database. Now I would like to use the subscription feature published in version 3.0.0. Unfortunately, the information about the application of the subsciption function is not very mature. How is the approach to achieve real-time functionality using graphql-java with subscriptions? As of recent graphql-java versions, subscriptions are fully supported. The DataFetcher for a subscription must return a org.reactivestreams.Publisher , and graphql-java will take care of mapping the query function over the results. The feature is

spring jar bootRun causes GraphQL Schema error

痞子三分冷 提交于 2019-12-02 16:18:12
问题 When I build my Spring Boot application using gradle bootRun or build and then run the output jar, I get the following enormous list of errors out of the console log. 2018-03-18 00:49:38.754 ERROR 228 --- [ main] o.s.boot.SpringApplication : Application startup failed org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat at org

spring jar bootRun causes GraphQL Schema error

自闭症网瘾萝莉.ら 提交于 2019-12-02 10:52:02
When I build my Spring Boot application using gradle bootRun or build and then run the output jar, I get the following enormous list of errors out of the console log. 2018-03-18 00:49:38.754 ERROR 228 --- [ main] o.s.boot.SpringApplication : Application startup failed org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh

How to upload files with graphql-java?

荒凉一梦 提交于 2019-12-01 03:51:30
问题 I can't find out how to upload files if i use graphql-java, can someone show me a demo? I will be appreciated! reference : https://github.com/graphql-java-kickstart/graphql-java-tools/issues/240 I tried it in springboot by using graphql-java-kickstart graphql-java-tools, but it didn't work @Component public class FilesUpload implements GraphQLMutationResolver { public Boolean testMultiFilesUpload(List<Part> parts, DataFetchingEnvironment env) { // get file parts from DataFetchingEnvironment,

Return HashMap<String, Object> from GraphQL-Java

耗尽温柔 提交于 2019-11-30 21:08:52
I tried few variant and had no luck to return a map in GraphQL. So I have the following two objects: public class Customer { private String name, age; // getters & setters } public class Person { private String type; private Map<String, Customer> customers; // getters & setters } My schema looks like this: type Customer { name: String! age: String! } type Person { type: String! customers: [Customer!] // Here I tried all combination but had no luck, is there a Map type support for GQL? } Can someone please tell me how to achieve this so that GraphQL magically process this or an alternative

Return HashMap<String, Object> from GraphQL-Java

别等时光非礼了梦想. 提交于 2019-11-30 17:01:50
问题 I tried few variant and had no luck to return a map in GraphQL. So I have the following two objects: public class Customer { private String name, age; // getters & setters } public class Person { private String type; private Map<String, Customer> customers; // getters & setters } My schema looks like this: type Customer { name: String! age: String! } type Person { type: String! customers: [Customer!] // Here I tried all combination but had no luck, is there a Map type support for GQL? } Can