Socket
Socket
Sign inDemoInstall

@faststore/graphql-utils

Package Overview
Dependencies
4
Maintainers
7
Versions
98
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.78 to 3.0.0

10

dist/index.d.ts
export declare const gql: (_: TemplateStringsArray) => never;
export interface GraphQLResponse<D = any> {
data: D;
errors: any[];
}
export interface RequestOptions<V = any> {
operationName: string;
variables: V;
fetchOptions?: RequestInit;
}
export declare const request: <V = any, D = any>(endpoint: string, { operationName, variables, fetchOptions }: RequestOptions<V>) => Promise<GraphQLResponse<D>>;

40

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.request = exports.gql = void 0;
exports.gql = void 0;
const gql = (_) => {
throw new Error(`[graphql-utils]: This should have been removed by the babel plugin. Please make sure the babel plugin is configured correctly`);
throw new Error(`[graphql-utils]: Depreciation notice: the gql function should be imported from @faststore/core. Follow this migration guide: faststore.dev/docs/migration/graphql-utils`);
};
exports.gql = gql;
const DEFAULT_HEADERS_BY_VERB = {
POST: {
'Content-Type': 'application/json',
},
};
const request = async (endpoint, { operationName, variables, fetchOptions }) => {
// Uses method from fetchOptions.
// If no one is passed, figure out with via heuristic
const method = fetchOptions?.method !== undefined
? fetchOptions.method.toUpperCase()
: operationName.endsWith('Query')
? 'GET'
: 'POST';
const params = new URLSearchParams({
operationName,
...(method === 'GET' && { variables: JSON.stringify(variables) }),
});
const body = method === 'POST'
? JSON.stringify({
operationName,
variables,
})
: undefined;
const url = `${endpoint}?${params.toString()}`;
const response = await fetch(url, {
method,
body,
...fetchOptions,
headers: {
...DEFAULT_HEADERS_BY_VERB[method],
...fetchOptions?.headers,
},
});
return response.json();
};
exports.request = request;
//# sourceMappingURL=index.js.map

8

package.json
{
"name": "@faststore/graphql-utils",
"version": "2.2.78",
"version": "3.0.0",
"description": "GraphQL utilities",

@@ -24,4 +24,4 @@ "repository": {

"devDependencies": {
"@faststore/eslint-config": "^2.2.78",
"@faststore/shared": "^2.2.78",
"@faststore/eslint-config": "^3.0.0",
"@faststore/shared": "^3.0.0",
"cross-env": "^7.0.2",

@@ -37,3 +37,3 @@ "eslint": "7.32.0",

},
"gitHead": "3c62fe1c0b2432c97a93a2be93f4c761d0ed546c"
"gitHead": "5352d481c0020af1d2f7e7286775fd5ad30ebcef"
}
export const gql = (_: TemplateStringsArray) => {
throw new Error(
`[graphql-utils]: This should have been removed by the babel plugin. Please make sure the babel plugin is configured correctly`
`[graphql-utils]: Depreciation notice: the gql function should be imported from @faststore/core. Follow this migration guide: faststore.dev/docs/migration/graphql-utils`
)
}
export interface GraphQLResponse<D = any> {
data: D
errors: any[]
}
export interface RequestOptions<V = any> {
operationName: string
variables: V
fetchOptions?: RequestInit
}
const DEFAULT_HEADERS_BY_VERB: Record<string, Record<string, string>> = {
POST: {
'Content-Type': 'application/json',
},
}
export const request = async <V = any, D = any>(
endpoint: string,
{ operationName, variables, fetchOptions }: RequestOptions<V>
): Promise<GraphQLResponse<D>> => {
// Uses method from fetchOptions.
// If no one is passed, figure out with via heuristic
const method =
fetchOptions?.method !== undefined
? fetchOptions.method.toUpperCase()
: operationName.endsWith('Query')
? 'GET'
: 'POST'
const params = new URLSearchParams({
operationName,
...(method === 'GET' && { variables: JSON.stringify(variables) }),
})
const body =
method === 'POST'
? JSON.stringify({
operationName,
variables,
})
: undefined
const url = `${endpoint}?${params.toString()}`
const response = await fetch(url, {
method,
body,
...fetchOptions,
headers: {
...DEFAULT_HEADERS_BY_VERB[method],
...fetchOptions?.headers,
},
})
return response.json()
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc