@devticon-os/graphql-codegen-axios 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +25 -2
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
- ### graphql-codegen-axios
1
+ ## graphql-codegen-axios
2
2
  A code generation tool that generates an Axios SDK based on your GraphQL queries. This tool makes it easy to consume GraphQL APIs in your Axios projects by automatically generating code for querying your GraphQL API and mapping the results to JavaScript objects.
3
3
 
4
4
  ### Features
5
5
  - Generates TypeScript code for querying GraphQL APIs with Axios.
6
- - Supports the @first, @firstOrFail, and @nonNullable directives.
6
+ - Supports the `@first`, `@firstOrFail`, and `@nonNullable` directives.
7
7
 
8
8
  ### Usage
9
9
  To use graphql-codegen-axios, you need to have Node.js installed on your system.
@@ -63,6 +63,29 @@ query GetFirstUser {
63
63
  }
64
64
  }
65
65
  ```
66
+ ### Field Selection
67
+ If your query selects only one field, it will be returned directly instead of being wrapped in an object. For example, the following query:
68
+
69
+ ```graphql
70
+ query getCats {
71
+ cats {
72
+ id
73
+ }
74
+ }
75
+ ```
76
+ Will generate code that directly returns the name field:
77
+
78
+ ```typescript
79
+ export const getSdk = (client: AxiosInstance) => ({
80
+ getCats: (variables: GetCatsQueryVariables, config?: AxiosRequestConfig) =>
81
+ client
82
+ .post<GraphqlResponse<GetCatsQuery>>('', { variables, query: getCatsRawQuery }, config)
83
+ .then(handleResponse) // returns data from axios response
84
+ .then(unpackSingleResults('cats')) // returns "cats" from GetCatsQuery object,
85
+ });
86
+
87
+ ```
88
+
66
89
  ### Generating Code
67
90
  You can generate the Axios SDK by running the following command:
68
91
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devticon-os/graphql-codegen-axios",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "license": "MIT",
5
5
  "main": "src/index.js",
6
6
  "repository": "https://github.com/devticon/graphql-codegen-axios",