【问题标题】:ArangoDB-Foxx with Relay Framework带有中继框架的 ArangoDB-Foxx
【发布时间】:2016-11-04 15:04:36
【问题描述】:

谁能告诉我或指向有关如何将 ArangoDB-Foxx 与 Relay Framework 一起使用的链接(或具体而言:relay-fullstack)?我到处找,没有运气。

我有一个使用 relay-fullstack 的 Relay 项目,我想让它与 ArangoDB-Foxx 一起工作(目前我正在使用来自 Relay 框架的 tutorial 的模式)。据我所知,ArangoDB-Foxx 使用graphql-sync 而不是graphql。所以它打破了relay-fullstack的构建过程。

任何帮助将不胜感激。谢谢.. :)

【问题讨论】:

    标签: arangodb graphql relayjs foxx


    【解决方案1】:

    我对 relay-fullstack 了解不多,但如果您唯一的问题是生成教程中提供的架构文件,只需检查它是如何生成的:https://github.com/relayjs/relay-starter-kit/blob/master/scripts/updateSchema.js

    使用最新版本的 graphql(或 graphql-sync),可以直接从包中导出 introspectionQueryprintSchema 实用程序。

    您可以通过创建一个名为 update-schema 的新 Foxx 脚本来模拟 Foxx 中的 updateSchema 脚本:

    首先将脚本添加到您的清单中:

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

    然后像这样将脚本本身实现为 scripts/updateSchema.js(假设您的 GraphQL 架构位于 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)
    )
    

    您现在可以从 Web 界面运行脚本,方法是进入服务的设置选项卡并从下拉列表中选择它(您不需要传递任何参数,只需按 OK)。该脚本应该为您的架构生成两个 JSON 和 GraphQL 文件,就像入门工具包中的那样。

    【讨论】:

    • 很好的答案。此外,您需要在 Foxx 中提供一个 api (GET) 以便将 schema.json 传递回您的 Relay 应用程序。在server/utils/babelRelayPlugin.js 中,您需要发出GET 请求,然后通过传递检索到的schema.json 来设置babel-relay-plugin
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多