graphql-java

LazyInitializationException with graphql-spring

▼魔方 西西 提交于 2019-12-21 03:45:50
问题 I am currently in the middle of migrating my REST-Server to GraphQL (at least partly). Most of the work is done, but i stumbled upon this problem which i seem to be unable to solve: OneToMany relationships in a graphql query, with FetchType.LAZY. I am using: https://github.com/graphql-java/graphql-spring-boot and https://github.com/graphql-java/graphql-java-tools for the integration. Here is an example: Entities: @Entity class Show { private Long id; private String name; @OneToMany private

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

五迷三道 提交于 2019-12-20 10:46:50
问题 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? 回答1: As of recent graphql-java versions, subscriptions are fully supported. The DataFetcher for a subscription must return a org.reactivestreams

GraphQl variable using grapiql - variable is undefined

柔情痞子 提交于 2019-12-18 09:51:44
问题 I am using this endpoint: @PostMapping("graphql") public ResponseEntity<Object> getResource(@RequestBody Object query) { // String query ExecutionResult result; if (query instanceof String) { result = graphQL.execute(query.toString()); // if plain text } else{ String queryString = ((HashMap) query).get("query").toString(); Object variables = ((HashMap) query).get("variables"); ExecutionInput input = ExecutionInput.newExecutionInput() .query(queryString) .variables((Map<String, Object>)

Access to protected field of parent object through child object via a query schema

冷暖自知 提交于 2019-12-11 17:05:13
问题 I am using graphql-spqr So that I don't have to create schema.graphql files. I have a base class in which most of my other classes inherit from. For example @GraphQLInterface(name = "BaseResponse", implementationAutoDiscovery = true) @ToString @Data public class BaseResponse { @JsonInclude(Include.NON_NULL) protected String responseCode; @JsonInclude(Include.NON_NULL) protected String responseDescription; protected String hash; } Other classes inherit from the above base class as below

GraphQL schema equivalent of this Json?

流过昼夜 提交于 2019-12-11 15:12:30
问题 I'm newbie to GraphQL, and was wondering if someone could help me figure out what is the equivalent of below JSON into GraphQL schema: [ { "id": "1", "name": "A", "fldDef": [ { "name": "f1", "type": "str", "opt": false }, { "name": "f2", "type": "bool" }] }, { "id": "2", "name": "B", "fldDef": [ { "name": "f3", "type": "str", "opt": true }, { "name": "f4", "type": "str", "opt": true }] } ] So far I managed to map above response to below object: public class FldDef { private String name, type;

GraphQL java send custom error in json format

烈酒焚心 提交于 2019-12-10 10:14:22
问题 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. 回答1: 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"

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

雨燕双飞 提交于 2019-12-07 10:00:41
问题 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 } 回答1: Yes, because the type system rules are very

How to get Query/Mutation operation name

随声附和 提交于 2019-12-06 15:50:43
I'm new to Spring boot + GraphQL. I need to get the Query/Mutation operation name inside my controller class. Purpose : Need to grand permission to some users to specific mutation/Query operations. Here the user type will be passed as a request header and will be validated and check whether the user is allowed to access that operation. @PostMapping public ResponseEntity<Object> callGraphQLService(@RequestBody String query, @RequestHeader("user") String userName) { ExecutionResult result = graphService.getGraphQL().execute(ExecutionInput.newExecutionInput() .query(query) .context(userName)

Java GraphQL - Pass field values to resolver for objects

橙三吉。 提交于 2019-12-06 09:28:57
I am looking to pass a field value to a resolved field using another object type. Another way to put it if I have `Customer > User > Profile' - how can I pass the CustomerID field value that would be in customer to Profile as an argument or variable in order to resolve correctly? There's exactly 5 possibilities (as of graphql-java v12) to provide info to a resolver ( DataFetcher ) at any level: 1) Directly pass them in the query (possibly on multiple levels): {customer(id: 3) { user { profile(id: 3) { name } } } } 2) Get values from the source object The source is the result of the enclosing

Validation error of type FieldUndefined: Field 'register' in type 'Query' is undefined

邮差的信 提交于 2019-12-06 07:39:16
I am new to GrapQL. I am trying to use it with spring boot. I can make query successfully, it is returning the data that I need, but i want now to use mutation. I need to add a use to database when he registers. This is my schema.graphqls file: type Token { token: String } type Register { message: String } type User { username: String! firstName: String! lastName: String! password: String! role: String! } type Query { login(username: String, password: String): Token } type Mutation { register(input: RegisterUserInput!): Register } input RegisterUserInput { username: String! firstName: String!