24
24
import static okhttp3 .MediaType .parse ;
25
25
26
26
import com .fasterxml .jackson .core .type .TypeReference ;
27
+ import com .kobylynskyi .graphql .codegen .model .graphql .GraphQLOperationRequest ;
28
+ import com .kobylynskyi .graphql .codegen .model .graphql .GraphQLRequest ;
29
+ import com .kobylynskyi .graphql .codegen .model .graphql .GraphQLResponseProjection ;
27
30
import com .spotify .github .Tracer ;
28
31
import com .spotify .github .jackson .Json ;
29
32
import com .spotify .github .v3 .Team ;
41
44
import com .spotify .github .v3 .repos .CommitItem ;
42
45
import com .spotify .github .v3 .repos .FolderContent ;
43
46
import com .spotify .github .v3 .repos .Repository ;
44
- import com .spotify .github .v3 .repos .Status ;
45
47
import com .spotify .github .v3 .repos .RepositoryInvitation ;
46
-
48
+ import com . spotify . github . v3 . repos . Status ;
47
49
import java .io .*;
48
50
import java .lang .invoke .MethodHandles ;
49
51
import java .net .URI ;
58
60
import java .util .function .Consumer ;
59
61
import javax .ws .rs .core .HttpHeaders ;
60
62
import javax .ws .rs .core .MediaType ;
61
-
62
63
import okhttp3 .*;
63
64
import org .apache .commons .io .FileUtils ;
64
65
import org .slf4j .Logger ;
@@ -447,7 +448,7 @@ Json json() {
447
448
*/
448
449
CompletableFuture <Response > request (final String path ) {
449
450
final Request request = requestBuilder (path ).build ();
450
- log .debug ("Making request to {}" , request .url (). toString () );
451
+ log .debug ("Making request to {}" , request .url ());
451
452
return call (request );
452
453
}
453
454
@@ -462,7 +463,7 @@ CompletableFuture<Response> request(final String path, final Map<String, String>
462
463
final Request .Builder builder = requestBuilder (path );
463
464
extraHeaders .forEach (builder ::addHeader );
464
465
final Request request = builder .build ();
465
- log .debug ("Making request to {}" , request .url (). toString () );
466
+ log .debug ("Making request to {}" , request .url ());
466
467
return call (request );
467
468
}
468
469
@@ -474,7 +475,7 @@ CompletableFuture<Response> request(final String path, final Map<String, String>
474
475
*/
475
476
<T > CompletableFuture <T > request (final String path , final Class <T > clazz ) {
476
477
final Request request = requestBuilder (path ).build ();
477
- log .debug ("Making request to {}" , request .url (). toString () );
478
+ log .debug ("Making request to {}" , request .url ());
478
479
return call (request )
479
480
.thenApply (body -> json ().fromJsonUncheckedNotNull (responseBodyUnchecked (body ), clazz ));
480
481
}
@@ -491,7 +492,7 @@ <T> CompletableFuture<T> request(
491
492
final Request .Builder builder = requestBuilder (path );
492
493
extraHeaders .forEach (builder ::addHeader );
493
494
final Request request = builder .build ();
494
- log .debug ("Making request to {}" , request .url (). toString () );
495
+ log .debug ("Making request to {}" , request .url ());
495
496
return call (request )
496
497
.thenApply (body -> json ().fromJsonUncheckedNotNull (responseBodyUnchecked (body ), clazz ));
497
498
}
@@ -510,7 +511,7 @@ <T> CompletableFuture<T> request(
510
511
final Request .Builder builder = requestBuilder (path );
511
512
extraHeaders .forEach (builder ::addHeader );
512
513
final Request request = builder .build ();
513
- log .debug ("Making request to {}" , request .url (). toString () );
514
+ log .debug ("Making request to {}" , request .url ());
514
515
return call (request )
515
516
.thenApply (
516
517
response ->
@@ -525,7 +526,7 @@ <T> CompletableFuture<T> request(
525
526
*/
526
527
<T > CompletableFuture <T > request (final String path , final TypeReference <T > typeReference ) {
527
528
final Request request = requestBuilder (path ).build ();
528
- log .debug ("Making request to {}" , request .url (). toString () );
529
+ log .debug ("Making request to {}" , request .url ());
529
530
return call (request )
530
531
.thenApply (
531
532
response ->
@@ -544,7 +545,7 @@ CompletableFuture<Response> post(final String path, final String data) {
544
545
requestBuilder (path )
545
546
.method ("POST" , RequestBody .create (parse (MediaType .APPLICATION_JSON ), data ))
546
547
.build ();
547
- log .debug ("Making POST request to {}" , request .url (). toString () );
548
+ log .debug ("Making POST request to {}" , request .url ());
548
549
return call (request );
549
550
}
550
551
@@ -563,7 +564,7 @@ CompletableFuture<Response> post(
563
564
.method ("POST" , RequestBody .create (parse (MediaType .APPLICATION_JSON ), data ));
564
565
extraHeaders .forEach (builder ::addHeader );
565
566
final Request request = builder .build ();
566
- log .debug ("Making POST request to {}" , request .url (). toString () );
567
+ log .debug ("Making POST request to {}" , request .url ());
567
568
return call (request );
568
569
}
569
570
@@ -603,18 +604,21 @@ <T> CompletableFuture<T> post(final String path, final String data, final Class<
603
604
/**
604
605
* Make a POST request to the graphql endpoint of Github
605
606
*
606
- * @param data request body as stringified JSON
607
+ * @param queryRequest GraphQLOperationRequest object with query or mutation request
608
+ * @param responseProjection Select what fields are required in the response
607
609
* @return response
608
610
*
609
611
* @see "https://docs.github.com/en/[email protected] /graphql/guides/forming-calls-with-graphql#communicating-with-graphql"
610
612
*/
611
- public CompletableFuture <Response > postGraphql (final String data ) {
613
+ public CompletableFuture <Response > queryGraphQL (final GraphQLOperationRequest queryRequest , final GraphQLResponseProjection responseProjection ) {
614
+ GraphQLRequest graphqlRequest = new GraphQLRequest (queryRequest , responseProjection );
615
+ String body = graphqlRequest .toQueryString ();
612
616
final Request request =
613
- graphqlRequestBuilder ()
614
- .method ("POST" , RequestBody .create (parse (MediaType .APPLICATION_JSON ), data ))
615
- .build ();
616
- log .info ("Making POST request to {}" , request .url ());
617
- return call (request );
617
+ graphqlRequestBuilder ()
618
+ .method ("POST" , RequestBody .create (parse (MediaType .APPLICATION_JSON ), body ))
619
+ .build ();
620
+ log .info ("Making GraphQL Query POST request to {}, with body {} " , request .url (), body );
621
+ return this . call (request );
618
622
}
619
623
620
624
/**
@@ -629,7 +633,7 @@ CompletableFuture<Response> put(final String path, final String data) {
629
633
requestBuilder (path )
630
634
.method ("PUT" , RequestBody .create (parse (MediaType .APPLICATION_JSON ), data ))
631
635
.build ();
632
- log .debug ("Making POST request to {}" , request .url (). toString () );
636
+ log .debug ("Making POST request to {}" , request .url ());
633
637
return call (request );
634
638
}
635
639
@@ -659,7 +663,7 @@ CompletableFuture<Response> patch(final String path, final String data) {
659
663
requestBuilder (path )
660
664
.method ("PATCH" , RequestBody .create (parse (MediaType .APPLICATION_JSON ), data ))
661
665
.build ();
662
- log .debug ("Making PATCH request to {}" , request .url (). toString () );
666
+ log .debug ("Making PATCH request to {}" , request .url ());
663
667
return call (request );
664
668
}
665
669
@@ -695,7 +699,7 @@ <T> CompletableFuture<T> patch(
695
699
.method ("PATCH" , RequestBody .create (parse (MediaType .APPLICATION_JSON ), data ));
696
700
extraHeaders .forEach (builder ::addHeader );
697
701
final Request request = builder .build ();
698
- log .debug ("Making PATCH request to {}" , request .url (). toString () );
702
+ log .debug ("Making PATCH request to {}" , request .url ());
699
703
return call (request )
700
704
.thenApply (
701
705
response -> json ().fromJsonUncheckedNotNull (responseBodyUnchecked (response ), clazz ));
@@ -709,7 +713,7 @@ <T> CompletableFuture<T> patch(
709
713
*/
710
714
CompletableFuture <Response > delete (final String path ) {
711
715
final Request request = requestBuilder (path ).delete ().build ();
712
- log .debug ("Making DELETE request to {}" , request .url (). toString () );
716
+ log .debug ("Making DELETE request to {}" , request .url ());
713
717
return call (request );
714
718
}
715
719
@@ -725,7 +729,7 @@ CompletableFuture<Response> delete(final String path, final String data) {
725
729
requestBuilder (path )
726
730
.method ("DELETE" , RequestBody .create (parse (MediaType .APPLICATION_JSON ), data ))
727
731
.build ();
728
- log .debug ("Making DELETE request to {}" , request .url (). toString () );
732
+ log .debug ("Making DELETE request to {}" , request .url ());
729
733
return call (request );
730
734
}
731
735
0 commit comments