Skip to content

Commit

Permalink
fix(types.ts): renname variableValues to variables, change record…
Browse files Browse the repository at this point in the history
… sub-field types
  • Loading branch information
TomokiMiyauci committed Aug 7, 2022
1 parent 1d85c6f commit 07ff058
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ import {
const req = new Request("<graphql-endpoint>"); // any Request
const [data, err] = await resolveRequest(req);
if (data) {
const { query, variableValues, operationName, extensions } = data;
const { query, variables, operationName, extensions } = data;
}
```

Expand All @@ -478,14 +478,14 @@ if (data) {

RequestResult:

| N | Name | Description |
| - | -------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| 1 | data | Bellow records &#124; `undefined`<br>GraphQL parameters. |
| | query | `string`<br>A Document containing GraphQL Operations and Fragments to execute. |
| | variableValues | `Record<string, json>` &#124; `null`<br>Values for any Variables defined by the Operation. |
| | operationName | `string` &#124; `null`<br>The name of the Operation in the Document to execute. |
| | extensions | `Record<string, json>` &#124; `null`<br>Reserved for implementors to extend the protocol however they see fit. |
| 2 | error | `HttpError` &#124; `undefined`<br>The base class that all derivative HTTP extend, providing a status and an expose property. |
| N | Name | Description |
| - | ------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| 1 | data | Bellow records &#124; `undefined`<br>GraphQL parameters. |
| | query | `string`<br>A Document containing GraphQL Operations and Fragments to execute. |
| | variables | `Record<string, json>` &#124; `null`<br>Values for any Variables defined by the Operation. |
| | operationName | `string` &#124; `null`<br>The name of the Operation in the Document to execute. |
| | extensions | `Record<string, json>` &#124; `null`<br>Reserved for implementors to extend the protocol however they see fit. |
| 2 | error | `HttpError` &#124; `undefined`<br>The base class that all derivative HTTP extend, providing a status and an expose property. |

#### Remark

Expand Down
2 changes: 1 addition & 1 deletion handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function createHandler(

return res;
}
const { query: source, variableValues, operationName } = data;
const { query: source, variables: variableValues, operationName } = data;

const res = createResponse({
schema,
Expand Down
10 changes: 5 additions & 5 deletions parses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ export function parseGraphQLParameters(
];
}

const { query, ...rest } = value;
const { query, variables = null, operationName = null, extensions = null } =
value as GraphQLParameters;

return [{
operationName: null,
variableValues: null,
extensions: null,
operationName,
variables,
extensions,
query,
...rest,
}];
}
18 changes: 9 additions & 9 deletions requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export type RequestResult = [data: GraphQLParameters] | [
* const req = new Request("<graphql-endpoint>"); // any Request
* const [data, err] = await resolveRequest(req);
* if (data) {
* const { query, variableValues, operationName, extensions } = data;
* const { query, variables, operationName, extensions } = data;
* }
* ```
*/
Expand Down Expand Up @@ -217,10 +217,10 @@ export function resolveGetRequest(req: Request): RequestResult {
createHttpError(Status.BadRequest, `The parameter is required. "query"`),
];
}
let variableValues: GraphQLParameters["variableValues"] | null = null;
const variables = url.searchParams.get("variables");
if (isString(variables)) {
const [data, err] = JSON.parse(variables);
let variables: GraphQLParameters["variables"] | null = null;
const variablesStr = url.searchParams.get("variables");
if (isString(variablesStr)) {
const [data, err] = JSON.parse(variablesStr);
if (err) {
return [
,
Expand All @@ -231,15 +231,15 @@ export function resolveGetRequest(req: Request): RequestResult {
];
}
if (isPlainObject(data)) {
variableValues = data;
variables = data;
}
}

const operationName = url.searchParams.get("operationName");

return [{
query: source,
variableValues,
variables,
operationName,
extensions: null,
}];
Expand Down Expand Up @@ -355,7 +355,7 @@ export async function resolvePostRequest(
return [{
query,
operationName,
variableValues: variables,
variables,
extensions: null,
}];
}
Expand All @@ -377,7 +377,7 @@ export async function resolvePostRequest(
return [{
query,
operationName: null,
variableValues: null,
variables: null,
extensions: null,
}];
}
Expand Down
26 changes: 13 additions & 13 deletions requests_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ it(
expect(result[1]).toBeUndefined();
expect(result[0]).toEqual({
query: "query",
variableValues: null,
variables: null,
operationName: null,
extensions: null,
});
Expand All @@ -269,7 +269,7 @@ it(
expect(result[1]).toBeUndefined();
expect(result[0]).toEqual({
query: "query",
variableValues: null,
variables: null,
operationName: null,
extensions: null,
});
Expand Down Expand Up @@ -314,7 +314,7 @@ it(
const result = resolveGetRequest(new BaseRequest(url.toString()));
expect(result[0]).toEqual({
query: `query`,
variableValues: {
variables: {
test: "test",
},
operationName: "query",
Expand Down Expand Up @@ -530,7 +530,7 @@ it(describePostTests, `application/json`, async (t) => {
expect(result[0]).toEqual({
query: "test",
operationName: null,
variableValues: null,
variables: null,
extensions: null,
});
expect(result[1]).toBeUndefined();
Expand All @@ -552,7 +552,7 @@ it(describePostTests, `application/json`, async (t) => {
expect(result[0]).toEqual({
query: "from body",
operationName: null,
variableValues: null,
variables: null,
extensions: null,
});
expect(result[1]).toBeUndefined();
Expand All @@ -573,7 +573,7 @@ it(describePostTests, `application/json`, async (t) => {
expect(result[0]).toEqual({
query: "from body",
operationName: null,
variableValues: null,
variables: null,
extensions: null,
});
expect(result[1]).toBeUndefined();
Expand Down Expand Up @@ -613,7 +613,7 @@ it(describePostTests, `application/json`, async (t) => {
expect(result[0]).toEqual({
query: "query",
operationName: null,
variableValues: null,
variables: null,
extensions: null,
});
expect(result[1]).toBeUndefined();
Expand All @@ -634,7 +634,7 @@ it(describePostTests, `application/json`, async (t) => {
expect(result[0]).toEqual({
query: "query",
operationName: null,
variableValues: { abc: [] },
variables: { abc: [] },
extensions: null,
});
expect(result[1]).toBeUndefined();
Expand Down Expand Up @@ -674,7 +674,7 @@ it(describePostTests, `application/json`, async (t) => {
expect(result[0]).toEqual({
query: "query",
operationName: "subscription",
variableValues: null,
variables: null,
extensions: null,
});
expect(result[1]).toBeUndefined();
Expand Down Expand Up @@ -719,7 +719,7 @@ it(
expect(result[0]).toEqual({
query: "test",
operationName: null,
variableValues: null,
variables: null,
extensions: null,
});
expect(result[1]).toBeUndefined();
Expand All @@ -740,7 +740,7 @@ it(
expect(result[0]).toEqual({
query: "test",
operationName: null,
variableValues: null,
variables: null,
extensions: null,
});
expect(result[1]).toBeUndefined();
Expand All @@ -762,7 +762,7 @@ it(
expect(result[0]).toEqual({
query: "test",
operationName: null,
variableValues: null,
variables: null,
extensions: null,
});
expect(result[1]).toBeUndefined();
Expand All @@ -784,7 +784,7 @@ it(
expect(result[0]).toEqual({
query: "from body",
operationName: null,
variableValues: null,
variables: null,
extensions: null,
});
expect(result[1]).toBeUndefined();
Expand Down
4 changes: 2 additions & 2 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ export type GraphQLParameters = {
query: string;

/** Values for any Variables defined by the Operation. */
variableValues: Record<string, json> | null;
variables: Record<string, unknown> | null;

/** The name of the Operation in the Document to execute. */
operationName: string | null;

/** Reserved for implementors to extend the protocol however they see fit. */
extensions: Record<string, json> | null;
extensions: Record<string, unknown> | null;
};

export type GraphQLRequiredArgs = {
Expand Down

0 comments on commit 07ff058

Please sign in to comment.