apollo-server-core
Advanced tools
Comparing version 1.3.5 to 1.3.6
@@ -115,2 +115,22 @@ "use strict"; | ||
var query = requestParams.query; | ||
var extensions = requestParams.extensions; | ||
if (isGetRequest && extensions) { | ||
try { | ||
extensions = JSON.parse(extensions); | ||
} | ||
catch (error) { | ||
throw new HttpQueryError(400, 'Extensions are invalid JSON.'); | ||
} | ||
} | ||
if (query === undefined && extensions && extensions.persistedQuery) { | ||
throw new HttpQueryError(200, JSON.stringify({ | ||
errors: [ | ||
{ | ||
message: 'PersistedQueryNotSupported', | ||
}, | ||
], | ||
}), true, { | ||
'Content-Type': 'application/json', | ||
}); | ||
} | ||
if (isGetRequest) { | ||
@@ -117,0 +137,0 @@ if (typeof query === 'string') { |
{ | ||
"name": "apollo-server-core", | ||
"version": "1.3.5", | ||
"version": "1.3.6", | ||
"description": "Core engine for Apollo GraphQL server", | ||
@@ -32,3 +32,3 @@ "main": "dist/index.js", | ||
"meteor-promise": "0.8.6", | ||
"typescript": "2.8.1" | ||
"typescript": "2.8.3" | ||
}, | ||
@@ -35,0 +35,0 @@ "peerDependencies": { |
@@ -104,7 +104,50 @@ import { | ||
let query = requestParams.query; | ||
let extensions = requestParams.extensions; | ||
if (isGetRequest && extensions) { | ||
// For GET requests, we have to JSON-parse extensions. (For POST | ||
// requests they get parsed as part of parsing the larger body they're | ||
// inside.) | ||
try { | ||
extensions = JSON.parse(extensions); | ||
} catch (error) { | ||
throw new HttpQueryError(400, 'Extensions are invalid JSON.'); | ||
} | ||
} | ||
if (query === undefined && extensions && extensions.persistedQuery) { | ||
// It looks like we've received an Apollo Persisted Query. Apollo Server | ||
// does not support persisted queries out of the box, so we should fail | ||
// fast with a clear error saying that we don't support APQs. (A future | ||
// version of Apollo Server may support APQs directly.) | ||
throw new HttpQueryError( | ||
// Return 200 to simplify processing: we want this to be intepreted by | ||
// the client as data worth interpreting, not an error. | ||
200, | ||
JSON.stringify({ | ||
errors: [ | ||
{ | ||
message: 'PersistedQueryNotSupported', | ||
}, | ||
], | ||
}), | ||
true, | ||
{ | ||
'Content-Type': 'application/json', | ||
}, | ||
); | ||
} | ||
if (isGetRequest) { | ||
if (typeof query === 'string') { | ||
// preparse the query incase of GET so we can assert the operation. | ||
// XXX This makes the type of 'query' in this function confused | ||
// which has led to us accidentally supporting GraphQL AST over | ||
// the wire as a valid query, which confuses users. Refactor to | ||
// not do this. Also, for a GET request, query really shouldn't | ||
// ever be anything other than a string or undefined, so this | ||
// set of conditionals doesn't quite make sense. | ||
query = parse(query); | ||
} else if (!query) { | ||
// Note that we've already thrown a different error if it looks like APQ. | ||
throw new HttpQueryError(400, 'Must provide query string.'); | ||
@@ -126,6 +169,9 @@ } | ||
const operationName = requestParams.operationName; | ||
let variables = requestParams.variables; | ||
if (typeof variables === 'string') { | ||
try { | ||
// XXX Really we should only do this for GET requests, but for | ||
// compatibility reasons we'll keep doing this at least for now for | ||
// broken clients that ship variables in a string for no good reason. | ||
variables = JSON.parse(variables); | ||
@@ -132,0 +178,0 @@ } catch (error) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78702
23
1626