graphql-java

Java GraphQL - Pass field values to resolver for objects

廉价感情. 提交于 2020-01-23 15:35:32
问题 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? 回答1: 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 {

Java GraphQL - Pass field values to resolver for objects

社会主义新天地 提交于 2020-01-23 15:35:02
问题 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? 回答1: 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 {

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

百般思念 提交于 2020-01-13 22:38:20
问题 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

Dynamic generate GraphQL schema supports

醉酒当歌 提交于 2020-01-12 05:54:36
问题 Is it possible to dynamically create a GraphQL schema ? We store the data in mongoDB and there is a possibility of new fields getting added. We do not want any code change to happen for this newly added field in the mongoDB document. Is there any way we can generate the schema dynamically ? Schema is defined in code, but for java(schema as pojo), when new attribute is added, you have to update and recompile code, then archive and deploy the jar again. Any way to generate schema by the data

How to expose graphql field with different name

穿精又带淫゛_ 提交于 2020-01-11 08:09:31
问题 I am exploring GraphQL and would like to know if there is any way of renaming the response field for example i have a POJO with these field class POJO { Long id; String name; } GraphQL query: type POJO { id: Long name: String } My response is something like this { "POJO" { "id": 123, "name": "abc" } } Can i rename the name field to something like userName so that my response is below { "POJO" { "id": 123, "userName": "abc" } } 回答1: You can use GraphQL Aliases to modify individual keys in the

SpringBoot GraphQL field name mismatch

删除回忆录丶 提交于 2020-01-06 06:35:51
问题 It seems that the names defined in the .graphqls file MUST match the field names in the POJO. Is there a way to maybe annotate the field so that they don't have to? For example, I have something like this in the graphqls file type Person { personId: ID! name: String! } Then in my Entity POJO I have like @Id @Column(name="PERSON_ID") @JsonProperty("person_id") private int personId; @Column(name="NAME") @JsonProperty("name") private String name; So, the intention is for the field name to be

how to use GraphQL from Java?

∥☆過路亽.° 提交于 2020-01-04 02:56:29
问题 Any webservice which supports GraphQL is consumable through a Java implementation? Because "it provides an alternative to REST..."? 回答1: Graphql-java (that you linked to) is an implementation of the GraphQL specification. As such, it is used to create GraphQL servers . A client doesn't need anything special to consume a service, just like it doesn't need anything special to consume a REST service - only to be be able to speak HTTP. You can use any generic HTTP client you like . Still, you

Inject bean into DataFetcher of GraphQL

有些话、适合烂在心里 提交于 2020-01-02 04:50: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

authentication in spring boot using graphql

拜拜、爱过 提交于 2019-12-31 21:34:56
问题 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

How to get Query/Mutation operation name

我与影子孤独终老i 提交于 2019-12-23 01:36:11
问题 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 =