Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fetchFromRemoteEndpoint({ request, options }) {
// Continue if uploads are possible
if (typeof FormData !== 'undefined') {
// Extract any files from the request variables
const files = extractFiles(request.variables, 'variables')
// Continue if there are files to upload
if (files.length) {
// Convert query AST to string for transport
request.query = printAST(request.query)
// Construct a multipart form
const formData = new FormData()
formData.append('operations', JSON.stringify(request))
files.forEach(({ path, file }) => formData.append(path, file))
// Send request
return fetch(this._uri, {
method: 'POST',
body: formData,
...options
})
}
}
// Standard fetch method fallback
fetchFromRemoteEndpoint({ request, options }) {
// Continue if uploads are possible
if (typeof FormData !== 'undefined') {
// Extract any files from the request variables
const files = extractFiles(request.variables, 'variables')
// Continue if there are files to upload
if (files.length) {
// Convert query AST to string for transport
request.query = printAST(request.query)
// Construct a multipart form
const formData = new FormData()
// formData.append('operations', JSON.stringify(request))
formData.append('query', request.query)
formData.append('operationName', request.operationName)
files.forEach(({ path, file }) => {
formData.append(path, file)
request.variables[path.replace("variables.", "")] = path
})
formData.append('variables', JSON.stringify(request.variables))
// Send request
return fetch(this._uri, {
method: 'POST',
body: formData,
public query(request: Request): Promise {
const { query, variables } = request;
return graphql(
this.schema,
printAST(query),
null,
null,
variables,
);
}
public getSchema(): GraphQLSchema {
requests.forEach(request => {
request.query = printAST(request.query)
})