使用 graphql 公开动态模式 [英] exposing dynamic schemas with graphql

查看:27
本文介绍了使用 graphql 公开动态模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序动态处理架构.用户可以上传新域或更改现有域的定义.例如,例如,我使用这样的用户架构发布产品:

My application handles schema on the fly. Users can upload new domains or change the definitions of existing domains. For ex, say, I ship the product with a user schema like this :

user { 
  fn, ln, age
}
Later user can change this definition to include new properties;
user { 
  fn, ln, age, 
  salary, address
}

或者他们可以添加一个全新的域概念.

or they can add an entirely new domain concept.

如果我使用 GraphQL,有没有办法动态更改架构?

If I use GraphQL, is there a way to change the schema dynamically ?

另一个问题是;我们的模式具有使模式的某些部分相关的条件.对于前;用户架构可能是这样的:

Another question is; Our schemas have conditions that make some parts of the schema relevant. For ex; the user schema may have something like this:

user {
  fn, ln, age, gender
  foo (if gender == Male)
  bar (if gender == Female)
}

GraphQL 中是否有规定来表达这些.我可以在 java 代码中处理它,但是,架构查找需要路由到我的代码,而不是引用静态架构注册表.

are there provisions in GraphQL to express these. I am ok to handle it in java code, but, then the schema look ups need to be routed to my code rather than referring to a static schema registry.

推荐答案

我不得不解决同样的问题:我有一个 graphQL java 服务器,它可以动态加载插件(每个插件都有自己的架构定义).

I had to solve the same kind of problem: I have a graphQL java server which can load plugins dynamically (each plugins come with its own schema definition).

您必须实现自己的GraphQLSchemaProvider并覆盖public GraphQLSchema getSchema(HttpServletRequest request).然后根据刷新时间/请求条件(即:用户)/其他任何内容加载/重新加载您的架构...

You have to implement your own GraphQLSchemaProviderand override public GraphQLSchema getSchema(HttpServletRequest request). Then load / reload your schema according to refresh time / request condition (ie: user) / anything else...

对于您的第二个问题,您可以使用内联片段 http://graphql.org/学习/查询/#inline-fragments

For your second question, you can use Inline fragment http://graphql.org/learn/queries/#inline-fragments

这篇关于使用 graphql 公开动态模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆