asubanovsky
asubanovsky

Reputation: 1748

ArangoDB-Foxx with Relay Framework

Can anyone tell me or point me to the link about how to use ArangoDB-Foxx along with Relay Framework (or to be specific: relay-fullstack)? I've looked everywhere and got no luck.

I have a Relay project using relay-fullstack and I want to make it working with ArangoDB-Foxx (currently I'm using a schema from Relay framework's tutorial). As I know, ArangoDB-Foxx uses graphql-sync instead of graphql. So it breaks the building process of relay-fullstack.

Any help would be very appreciated. Thanks.. :)

Upvotes: 2

Views: 429

Answers (1)

Alan Plum
Alan Plum

Reputation: 10892

I don't know much about relay-fullstack but if your only problem is generating the schema file provided in the tutorial, just check how it is generated: https://github.com/relayjs/relay-starter-kit/blob/master/scripts/updateSchema.js

With the latest version of graphql (or graphql-sync) the introspectionQuery and printSchema utilities are exported from the package directly.

You can emulate the updateSchema script in Foxx by creating a new Foxx script called update-schema:

First add the script to your manifest:

"scripts": {
  "update-schema": "scripts/updateSchema.js"
}

Then implement the script itself as scripts/updateSchema.js like so (assuming your GraphQL schema lives in data/schema.js):

'use strict'
const fs = require('fs')
const path = require('path')
const Schema = require('../data/schema')
const gql = require('graphql')

const result = gql.graphql(Schema, gql.introspectionQuery)
if (result.errors) {
  console.error(
    'ERROR introspecting schema: ',
    JSON.stringify(result.errors.map((err) => gql.formatError(err)), null, 2)
  )
} else {
  fs.writeFileSync(
    path.join(__dirname, '../data/schema.json'),
    JSON.stringify(result, null, 2)
  )
}
fs.writeFileSync(
  path.join(__dirname, '../data/schema.graphql'),
  gql.printSchema(Schema)
)

You can now run the script from the web interface by going into the settings tab of your service and picking it from the dropdown (you don't need to pass any arguments, just press OK). The script should generate the two JSON and GraphQL files for your schema like the one in the starter kit does.

Upvotes: 3

Related Questions