Mit NodeJS gibt graphQLHTTP
von express-graphql
ist, die wie folgt übergeben werden können:Mit GraphiQL mit Foxx
const {Schema} = require('./data/schema');
const graphQLApp = express();
graphQLApp.use('/', graphQLHTTP({
graphiql: true,
pretty: true,
schema: Schema,
}));
Mit dieser Art von Konfiguration können wir GraphiQL verwenden. Wie erreiche ich das mit Foxx? Von this repo konnte ich sehen, dass Foxx graphql-sync
stattdessen verwendet. Ich durchsucht den Quellcode und ich fand es hier:
controller.js
'use strict';
const Foxx = require('org/arangodb/foxx');
const schema = require('./schema');
const graphql = require('graphql-sync').graphql;
const formatError = require('graphql-sync').formatError;
const ctrl = new Foxx.Controller(applicationContext);
// This is a regular Foxx HTTP API endpoint.
ctrl.post('/graphql', function (req, res) {
// By just passing the raw body string to graphql
// we let the GraphQL library take care of making
// sure the query is well-formed and valid.
// Our HTTP API doesn't have to know anything about
// GraphQL to handle it.
const result = graphql(schema, req.rawBody(), null, req.parameters);
console.log(req.parameters);
if (result.errors) {
res.status(400);
res.json({
errors: result.errors.map(function (error) {
return formatError(error);
})
});
} else {
res.json(result);
}
})
.summary('GraphQL endpoint')
.notes('GraphQL endpoint for the Star Wars GraphQL example.');
Ist es möglich, GraphiQL mit Foxx zu benutzen? Wenn JA, wie erreiche ich das? Irgendwelche Gedanken?
Danke.
Wow, das ist cool. Vielen Dank .. :) – asubanovsky
Wir haben uns Express-Graphql angeschaut und überlegt, es direkt zu ArangoDB zu portieren. Bis wir diesen Anruf tätigen, ist dies die beste Lösung. +1 –