View Javadoc

1   /*
2    * Copyright 2015 Data Archiving and Networked Services (an institute of
3    * Koninklijke Nederlandse Akademie van Wetenschappen), King's College London,
4    * Georg-August-Universitaet Goettingen Stiftung Oeffentlichen Rechts
5    *
6    * Licensed under the EUPL, Version 1.1 or – as soon they will be approved by
7    * the European Commission - subsequent versions of the EUPL (the "Licence");
8    * You may not use this work except in compliance with the Licence.
9    * You may obtain a copy of the Licence at:
10   *
11   * https://joinup.ec.europa.eu/software/page/eupl
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the Licence is distributed on an "AS IS" basis,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the Licence for the specific language governing
17   * permissions and limitations under the Licence.
18   */
19  
20  package eu.ehri.project.graphql;
21  
22  import com.fasterxml.jackson.annotation.JsonCreator;
23  import com.fasterxml.jackson.annotation.JsonProperty;
24  import com.google.common.collect.Maps;
25  
26  import java.util.Collections;
27  import java.util.Map;
28  
29  public class GraphQLQuery {
30  
31      private final String query;
32      private final Map<String, Object> variables;
33      private final String operationName;
34  
35      @JsonCreator
36      public GraphQLQuery(@JsonProperty("query") String query,
37              @JsonProperty("variables") Map<String, Object> variables,
38              @JsonProperty("operationName") String operationName) {
39          this.query = query;
40          this.variables = variables;
41          this.operationName = operationName;
42      }
43  
44      public GraphQLQuery(String query) {
45          this(query, Collections.emptyMap(), null);
46      }
47  
48      public String getQuery() {
49          return query;
50      }
51  
52      public Map<String, Object> getVariables() {
53          return variables != null ? variables : Collections.emptyMap();
54      }
55  
56      public String getOperationName() {
57          return operationName;
58      }
59  
60      @Override
61      public String toString() {
62          Map<String, Object> m = Maps.newHashMap();
63          m.put("query", query);
64          m.put("variables", variables);
65          return m.toString();
66      }
67  }