-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
11 additions
and
5 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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
// TODO: Improve README further | ||
|
||
Generating schema.json | ||
graphql-client introspect-schema --output PATH_TO_SOMEWHERE HASURA_ENDPOINT/v1/graphql --header 'x-hasura-role: SOME_HASURA_ROLE' | ||
## GraphQL Code Generation | ||
Querying a GraphQL requires informing Rust of the correct types to deserialize the response data into. In order to do this, the schema of the GraphQL data needs to be introspected. Following that, the query intended to be called needs to be fully defined. With this information, code can be generated using the graphql-client API. Below are the instructions on how to do so. | ||
|
||
Generating Rust types file for query | ||
graphql-client generate --schema-path PATH_TO_SCHEMA_JSON --response-derives 'Debug' --output-directory PATH_TO_GRAPHQL_QUERIES_FOLDER PATH_TO_QUERY_GRAPHQL_FILE | ||
After the codegen comples, you may need to manually modify the file further to resolve issues such as "super::date" not being found. | ||
### Generating schema.json | ||
Run the following command with the relevant sections replaced. It will create a JSON containing schemas for ALL tables under some Hasura Role. | ||
`graphql-client introspect-schema --output PATH_TO_SOMEWHERE HASURA_ENDPOINT/v1/graphql --header 'x-hasura-role: SOME_HASURA_ROLE'` | ||
|
||
### Generating Rust types file for query | ||
Run the following command with the correct arguments to generate a Rust file containing Structs and Modules to deserialize GraphQL responses for that particular query. After the codegen completes, you may need to manually modify the file further to resolve type issues. For example, replacing `super::date` with `String`. | ||
`graphql-client generate --schema-path PATH_TO_SCHEMA_JSON --response-derives 'Debug' --output-directory PATH_TO_GRAPHQL_QUERIES_FOLDER PATH_TO_QUERY_GRAPHQL_FILE` |
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