Skip to content

Commit

Permalink
add extensions to GraphQLParams
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloSzx committed Aug 20, 2021
1 parent 7e33e77 commit 1ea774a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/core/src/get-graphql-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@ import type { GraphQLParams, Request } from "./types";
export const getGraphQLParameters = (request: Request): GraphQLParams => {
const { body, method, query: queryParams } = request;

let operationName;
let query;
let variables;
let operationName: GraphQLParams["operationName"];
let query: GraphQLParams["query"];
let variables: GraphQLParams["variables"];
let extensions: GraphQLParams["extensions"];

if (isHttpMethod("GET", method)) {
operationName = queryParams.operationName;
query = queryParams.query;
variables = queryParams.variables;
} else if (isHttpMethod("POST", method)) {
operationName = body?.operationName;
query = body?.query;
variables = body?.variables;
extensions = queryParams.extensions;
} else if (isHttpMethod("POST", method) && body) {
operationName = body.operationName;
query = body.query;
variables = body.variables;
extensions = body.extensions;
}

return {
operationName,
query,
variables,
extensions,
};
};
5 changes: 5 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface GraphQLParams {
operationName?: string;
query?: string;
variables?: string | { [name: string]: any };
extensions?: string | Record<string, unknown>;
}

export interface ProcessRequestOptions<TContext, TRootValue> {
Expand Down Expand Up @@ -84,6 +85,10 @@ export interface ProcessRequestOptions<TContext, TRootValue> {
* Values for any Variables defined by the Operation.
*/
variables?: string | { [name: string]: any };
/**
* Extensions specified in request
*/
extensions?: string | Record<string, unknown>;
}

export interface FormatPayloadParams<TContext, TRootValue> {
Expand Down

0 comments on commit 1ea774a

Please sign in to comment.