Skip to content

Commit 1864755

Browse files
committed
add hello field
add example query script
1 parent fe69da7 commit 1864755

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

book-details/example-request.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
curl -vvv -X POST -H "Content-Type: application/json" -d '{"query":"{hello}"}' http://localhost:8080/graphql
2+
echo

book-details/src/main/java/com/graphqljava/tutorial/bookdetails/GraphQLDataFetchers.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,10 @@ public DataFetcher getAuthorDataFetcher() {
6060
.orElse(null);
6161
};
6262
}
63+
64+
public DataFetcher helloDataFetcher() {
65+
return dataFetchingEnvironment -> {
66+
return "world";
67+
};
68+
}
6369
}

book-details/src/main/java/com/graphqljava/tutorial/bookdetails/GraphQLProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ private GraphQLSchema buildSchema(String sdl) {
4545
private RuntimeWiring buildWiring() {
4646
return RuntimeWiring.newRuntimeWiring()
4747
.type(newTypeWiring("Query")
48-
.dataFetcher("bookById", graphQLDataFetchers.getBookByIdDataFetcher()))
48+
.dataFetcher("bookById", graphQLDataFetchers.getBookByIdDataFetcher())
49+
.dataFetcher("hello", graphQLDataFetchers.helloDataFetcher())
50+
)
4951
.type(newTypeWiring("Book")
5052
.dataFetcher("author", graphQLDataFetchers.getAuthorDataFetcher()))
5153
.build();

book-details/src/main/resources/schema.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
type Query {
2+
hello: String
23
bookById(id: ID): Book
34
}
45

0 commit comments

Comments
 (0)