graphql-ready
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -35,19 +35,28 @@ | ||
resolver, | ||
}) => ghttp((req, res) => { | ||
const startTime = Date.now() | ||
}) => ghttp(async (req, res) => { | ||
const startTime = Date.now() | ||
return { | ||
schema: buildSchema(schema, resolver), | ||
rootValue: api, | ||
graphiql: true, | ||
formatError: error => ({ | ||
message: error.message, | ||
stack: error.stack | ||
}), | ||
extensions: () => ({ | ||
took: Date.now() - startTime, | ||
}), | ||
} | ||
const rootValue = typeof api === 'function' ? await api(req) : api | ||
return { | ||
schema: buildSchema(schema, resolver), | ||
rootValue, | ||
graphiql: true, | ||
formatError: error => ({ | ||
message: error.message, | ||
stack: error.stack | ||
}), | ||
extensions: ({ | ||
result, | ||
}) => { | ||
if (Array.isArray(result.errors) && result.errors.length > 0) { | ||
res.status(400) | ||
} | ||
return { | ||
took: Date.now() - startTime, | ||
} | ||
}, | ||
} | ||
}) | ||
exports.graphiql = graphiql |
{ | ||
"name": "graphql-ready", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "make graphql ready for start", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -16,2 +16,3 @@ | ||
type Query { | ||
error: JSON | ||
echo(message: JSON!): JSON | ||
@@ -23,5 +24,8 @@ groups: Groups | ||
const api = { | ||
error () { | ||
throw new Error('error happend') | ||
}, | ||
echo ({message}) { | ||
return message | ||
} | ||
}, | ||
} | ||
@@ -28,0 +32,0 @@ |
3763
91