-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/babyfish-ct/graphql-provider
- Loading branch information
Showing
8 changed files
with
205 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,113 @@ Its development speed is very fast, and the usage method is very simple. | |
## Run the example | ||
Use intellij the open the [example](https://github.com/babyfish-ct/graphql-provider/tree/main/example), after waiting for gradle to finish all tasks, start the program and visit http://localhost:8080/graphiql. | ||
|
||
> The query "findBooks" is pagination query, so you must specify the argument "first" or "last". Otherwise, exeption will be thrown | ||
In order to experience this example, there are three things to note | ||
|
||
1. *Query.books* is pagination query, so you must specify the argument "first" or "last", like this | ||
``` | ||
query { | ||
books(first: 10) { | ||
edges { | ||
node { | ||
name | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
Otherwise, exeption will be thrown | ||
``` | ||
{ | ||
"errors": [ | ||
{ | ||
"message": "java.lang.IllegalArgumentException: neither 'first' nor 'last' is specified", | ||
"locations": [], | ||
"path": [ | ||
"books" | ||
], | ||
"extensions": { | ||
"errorType": "INTERNAL" | ||
} | ||
} | ||
], | ||
"data": { | ||
"books": null | ||
} | ||
} | ||
``` | ||
2. *BookStore.avgPrice*, *Query.myFavoriteBooks*, *Mutation.like* and *Mutation.unlike* are not open to anonymous users | ||
Look at this query | ||
``` | ||
query { | ||
books(first: 10) { | ||
edges { | ||
node { | ||
name | ||
store { | ||
name | ||
avgPrice # Access BookStore.avgPrice | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
*BookStore.avgPrice* is not open to anonymous users, spring security throws *AccessDeniedException* when *Authorization* of HTTP request header is not specified. | ||
You can login | ||
- by graphql way | ||
``` | ||
query { | ||
login(email: "[email protected]", password: "123456") { | ||
accessToken | ||
} | ||
} | ||
``` | ||
- or by rest way | ||
http://localhost:8080/authentication/[email protected]&password=123456 | ||
No matter which way you use, you can get the *accessToken*. Copy the *accessToken* and make the following HTTP header for the originally rejected graphql request | ||
```` | ||
{ "Authorization": "...paste AccessToken here..."} | ||
```` | ||
3. *Mutation.saveBook*, *Mutation.saveBooks*, *Mutation.saveShallowTree* and *Mutation.saveBookDeepTree* are only open to administrators. | ||
``` | ||
mutation { | ||
saveBook(input: { | ||
name: "NewBook", | ||
price: 70 | ||
}) { | ||
id | ||
} | ||
} | ||
``` | ||
This mutation can only be executed by admininstor, spring security throws *AccessDeniedException* when the current user is not administrator. | ||
You can login as administrator *([email protected])* | ||
- by graphql way | ||
``` | ||
query { | ||
login(email: "[email protected]", password: "123456") { | ||
accessToken | ||
} | ||
} | ||
``` | ||
- or by rest way | ||
http://localhost:8080/authentication/[email protected]&password=123456 | ||
No matter which way you use, you can get the *accessToken* of administrator. Copy the *accessToken* of administrator and make the following HTTP header for the originally rejected graphql request | ||
```` | ||
{ "Authorization": "...paste AccessToken of administrator here..."} | ||
```` | ||
## User guide & Documentation | ||
These links are not only user guides, but also documentation. | ||
|
@@ -35,6 +140,7 @@ Although the [example](https://github.com/babyfish-ct/graphql-provider/tree/main | |
7. [Pagination query](./doc/pagination.md) | ||
8. [Map inputs](./doc/input-mapper.md) | ||
9. [Execute Mutation](./doc/mutation.md) | ||
10. Security(Will come soon) | ||
----------- | ||
## Other projects | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.