33
33
*/
34
34
public class ApiGraphQLClient {
35
35
36
+ private static final String DB_ID = "<change_me>" ;
37
+ private static final String DB_REGION = "<change_me>" ;
38
+ private static final String DB_TOKEN = "<change_me>" ;
39
+
40
+
36
41
private static final String URL = "https://"
37
- + "3ed83de7-d97f-4fb6-bf9f-82e9f7eafa23-"
38
- + "eu-west-1"
39
- + ".apps.astra.datastax.com/api/"
40
- + "graphql-schema" ;
41
- private static final String TOKEN =
42
- "AstraCS:gdZaqzmFZszaBTOlLgeecuPs:edd25600df1c01506f5388340f138f277cece2c93cb70f4b5fa386490daa5d44" ;
42
+ + DB_ID + "-" + DB_REGION
43
+ + ".apps.astra.datastax.com/api/graphql-schema" ;
43
44
44
45
public static <T > GraphQLResponseEntity <T > callGraphQLService (String query , Class <T > clazz )
45
46
throws Exception {
46
-
47
- GraphQLTemplate graphQLTemplate = new GraphQLTemplate ();
48
-
49
47
Map <String , String > headers = new HashMap <>();
50
- headers .put ("x-cassandra-token" , TOKEN );
51
-
52
- GraphQLRequestEntity requestEntity = GraphQLRequestEntity .Builder ()
53
- .url (URL )
54
- .request (query )
55
- .headers (headers )
56
- .build ();
57
- return graphQLTemplate .query (requestEntity , clazz );
48
+ headers .put ("x-cassandra-token" , DB_TOKEN );
49
+ return new GraphQLTemplate ().query (GraphQLRequestEntity .Builder ()
50
+ .url (URL )
51
+ .request (query )
52
+ .headers (headers )
53
+ .build (), clazz );
58
54
}
59
55
60
56
/**
@@ -63,18 +59,18 @@ public static <T> GraphQLResponseEntity<T> callGraphQLService(String query, Clas
63
59
public static void main (String [] args )
64
60
throws Exception {
65
61
66
- // Building a request (with DSG codegen)
62
+ // List Keyspaces
67
63
GraphQLQueryRequest graphQLQueryRequest =
68
64
new GraphQLQueryRequest (
69
65
new KeyspacesGraphQLQuery .Builder ().build (),
70
66
new KeyspacesProjectionRoot ().name ());
71
67
72
- // Executing query (with American Express Nodes)
68
+ // Executing query
73
69
GraphQLResponseEntity <KeyspaceList > res = callGraphQLService (
74
70
graphQLQueryRequest .serialize (),
75
71
KeyspaceList .class );
76
72
77
- System . out . println ( "Keyspaces" );
73
+ // Showing results
78
74
res .getResponse ().getKeyspaces ().stream ().forEach (ks -> {
79
75
System .out .println (ks .getName ());
80
76
});
0 commit comments