Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gdorsi/mercurius into gdo…
Browse files Browse the repository at this point in the history
…rsi-master
  • Loading branch information
mcollina committed Dec 20, 2021
2 parents 86da408 + 4d185dd commit bef9669
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 180 deletions.
126 changes: 0 additions & 126 deletions examples/graphql-shield-authorization.js

This file was deleted.

23 changes: 15 additions & 8 deletions index.js
Expand Up @@ -535,7 +535,14 @@ const plugin = fp(async function (app, opts) {
const shouldCompileJit = cached && cached.count++ === minJit
// Validate variables
if (variables !== undefined && !shouldCompileJit) {
const executionContext = buildExecutionContext(fastifyGraphQl.schema, document, root, context, variables, operationName)
const executionContext = buildExecutionContext({
schema: fastifyGraphQl.schema,
document,
rootValue: root,
contextValue: context,
variableValues: variables,
operationName
})
if (Array.isArray(executionContext)) {
const err = new MER_ERR_GQL_VALIDATION()
err.errors = executionContext
Expand Down Expand Up @@ -566,14 +573,14 @@ const plugin = fp(async function (app, opts) {
return maybeFormatErrors(execution, context)
}

const execution = await execute(
modifiedSchema || fastifyGraphQl.schema,
modifiedDocument || document,
root,
context,
variables,
const execution = await execute({
schema: modifiedSchema || fastifyGraphQl.schema,
document: modifiedDocument || document,
rootValue: root,
contextValue: context,
variableValues: variables,
operationName
)
})

return maybeFormatErrors(execution, context)
}
Expand Down
47 changes: 14 additions & 33 deletions lib/errors.js
Expand Up @@ -26,39 +26,20 @@ class FederatedError extends Error {
// allows to copy the `path` & `locations` properties
// from the already serialized error
function toGraphQLError (err) {
return Object.create(GraphQLError, {
name: {
value: err.name
},
message: {
value: err.message,
enumerable: true,
writable: true
},
locations: {
value: err.locations || undefined,
enumerable: true
},
path: {
value: err.path || undefined,
enumerable: true
},
nodes: {
value: err.nodes || undefined
},
source: {
value: err.source || undefined
},
positions: {
value: err.positions || undefined
},
originalError: {
value: err.originalError || undefined
},
extensions: {
value: err.extensions || undefined
}
})
const gqlError = new GraphQLError(
err.message,
err.nodes,
err.source,
err.positions,
err.path,
err.originalError,
err.extensions
)

gqlError.locations = err.locations
gqlError.name = err.name

return gqlError
}

function defaultErrorFormatter (err, ctx) {
Expand Down
1 change: 1 addition & 0 deletions lib/federation.js
Expand Up @@ -129,6 +129,7 @@ function getStubTypes (schemaDefinitions, isGateway) {

function gatherDirectives (type) {
let directives = []
/* istanbul ignore else seems that extensionASTNodes is always provided in graphql16+, we are keeping this check for safety */
if (type.extensionASTNodes) {
for (const node of type.extensionASTNodes) {
/* istanbul ignore else we are not interested in nodes that does not have directives */
Expand Down
2 changes: 1 addition & 1 deletion lib/gateway/make-resolver.js
Expand Up @@ -39,7 +39,7 @@ function getDirectiveSelection (node, directiveName) {
}

function getDirectiveRequiresSelection (selections, type) {
if (!type.extensionASTNodes ||
if (!type.extensionASTNodes || type.extensionASTNodes.length === 0 ||
!type.extensionASTNodes[0].fields[0] ||
!type.extensionASTNodes[0].fields[0].directives[0]) {
return []
Expand Down
10 changes: 5 additions & 5 deletions lib/subscription-connection.js
Expand Up @@ -183,11 +183,11 @@ module.exports = class SubscriptionConnection {
subscriptionLoaders = this.fastify[kSubscriptionFactory]
}

const subIter = await subscribe(
const subIter = await subscribe({
schema,
document,
{}, // rootValue
{
rootValue: {},
contextValue: {
...context,
get __currentQuery () {
return print(document)
Expand All @@ -201,9 +201,9 @@ module.exports = class SubscriptionConnection {
[kEntityResolvers]: this.entityResolvers
}
},
variables,
variableValues: variables,
operationName
)
})
this.subscriptionIters.set(id, subIter)

if (subIter.errors) {
Expand Down
6 changes: 2 additions & 4 deletions package.json
Expand Up @@ -26,7 +26,7 @@
},
"homepage": "https://mercurius.dev",
"peerDependencies": {
"graphql": "^15.5.1"
"graphql": "^16.0.0"
},
"devDependencies": {
"@graphql-tools/merge": "^8.0.0",
Expand All @@ -41,8 +41,6 @@
"concurrently": "^6.2.0",
"docsify-cli": "^4.4.3",
"fastify": "^3.18.1",
"graphql-middleware": "^6.0.10",
"graphql-shield": "^7.5.0",
"graphql-tools": "^8.0.0",
"pre-commit": "^1.2.2",
"proxyquire": "^2.1.3",
Expand All @@ -62,7 +60,7 @@
"fastify-plugin": "^3.0.0",
"fastify-static": "^4.2.2",
"fastify-websocket": "^4.0.0",
"graphql": "^15.5.1",
"graphql": "^16.0.0",
"graphql-jit": "^0.7.0",
"mqemitter": "^4.4.1",
"p-map": "^4.0.0",
Expand Down
1 change: 0 additions & 1 deletion tap-snapshots/test/federation.js.test.cjs
Expand Up @@ -43,5 +43,4 @@ type User {
}
union _Entity = Product | User
`
4 changes: 2 additions & 2 deletions test/subscription-connection.js
Expand Up @@ -295,7 +295,7 @@ test('subscription connection send error message when client message type is inv
}))
})

test('subscription connection handles GQL_START message correctly, when payload.query is not defined', async (t) => {
test('subscription connection handles GQL_START message correctly, when payload.query is not defined', (t) => {
t.plan(1)

const sc = new SubscriptionConnection({
Expand All @@ -311,7 +311,7 @@ test('subscription connection handles GQL_START message correctly, when payload.

sc.isReady = true

await sc.handleMessage(JSON.stringify({
sc.handleMessage(JSON.stringify({
id: 1,
type: 'start',
payload: { }
Expand Down

0 comments on commit bef9669

Please sign in to comment.