我的困境始于将我的 graphql 模式从单个 .graphql 文件扩展到多个文件的简单愿望,这样我就可以更好地组织模式,这样它就不会变成一个失控的大文件。
我的原始布局非常简单,我在schema.graphql
文件中有一个工作模式。我将能够使用importSchema('server/schema.graphql')
graphql-import 库将其解析为字符串,该库现已弃用https://github.com/ardatan/graphql-import
他们提到它已合并到graphql-tools
最新版本中,并在此处提供迁移教程https://www.graphql-tools.com/docs/migration-from-import该教程似乎非常简单,因为他们的第一个示例几乎说明了正是我的代码的样子(除了我不使用 es6 导入但旧的 fashoined 需要):
import { importSchema } from 'graphql-import';
import { makeExecutableSchema } from 'graphql-tools';
const typeDefs = importSchema(join(__dirname, 'schema.graphql'));
const resolvers = {
Query: {...}
};
const schema = makeExecutableSchema({ typeDefs, resolvers });
Run Code Online (Sandbox Code Playgroud)
然后他们说要修改它,只需进行这些更改
import { loadSchemaSync } from '@graphql-tools/load';
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
import { addResolversToSchema } from '@graphql-tools/schema';
const schema = loadSchemaSync(join(__dirname, 'schema.graphql'), { loaders: [new GraphQLFileLoader()] …
Run Code Online (Sandbox Code Playgroud) 我想创建mutation apis,其中输入可以是不同的类型,比如我们在类型中拥有的接口。我知道我们不能在输入类型中有接口,我想知道我们如何在一个输入中支持多种输入类型。为了解释这个问题,我使用了一个虚拟示例:
input CreateCatInput{
id: String
name: String
}
input CreateDogInput{
id: String
name: String
breed: String
}
input CreateElephantInput{
id: String
name: String
weight: String
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我们想为它编写 apis,我将不得不为每种类型编写 api
createCat(input: CreateCatInput!)
createDog(input: CreateDogInput!)
createElephant(input: CreateElephantInput!)
Run Code Online (Sandbox Code Playgroud)
我对这种方法的问题是:
我正在寻找的解决方案是我只有一个 api :
createAnimal(input: CreateAnimalInput!)
Run Code Online (Sandbox Code Playgroud)
由于目前没有接口支持,公司如何实现可以是多种类型的输入?如何定义输入,以便我只能在 api 中提供一个输入?
我已经阅读了这个建议,但它涉及定义注释,我目前正在尝试。我想看看其他人是如何解决这个问题的。
编辑:看起来现在已经在这个主题上做了很多工作https://github.com/graphql/graphql-spec/pull/733并且该功能将很快可用。
我正在使用 Apollo Server 编写 GraphQL 和 REST 服务之间的 GraphQL 接口。该接口将为 Apollo 客户端前端提供单个 GraphQL 端点。
目前唯一的服务是 KeystoneJS 应用程序,它通过(据我所知)Apollo Server 提供 GraphQL 端点。为了暂时简单起见,我从 KeystoneJS 服务器 GraphQL Playground 下载 GraphQL 架构,并将其用作我的界面的 GraphQL 架构(在删除 Keystone 生成且 Apollo Server 无法理解的定义之后)。
我想自动化这个过程——也就是说,以某种方式“抓取”KeystoneJS/Apollo Server 生成的 GraphQL 模式,就像我从 GraphQL Playground 下载它一样。有没有办法从端点做到这一点?(我不想触及 KeystoneJS 内部结构,只需通过端点访问模式)
我刚开始将 amplify 与 GraphQL 结合使用。我正在设置数据库模式并在运行放大推送后自动生成函数。
\n我想要实现但不知道如何实现的目标
\n当调用API生成的函数来获取用户时,
\nlet user = await API.graphql(graphqlOperation(getUser,{id:userId}))\n
Run Code Online (Sandbox Code Playgroud)\n我正在获取一个用户对象,但是,它看起来像这样 - 即使我确信数据库中的数据设置正确。
\nbuttons: {nextToken: null} -- WANT THIS TO INCLUDE ACTUAL INFORMATION ABOUT BUTTONS CONNECTED TO THIS USER\ncreatedAt: "2020-09-02T23:41:12.278Z"\ncustomStyles: {id: "e3d1bbef-ec6f-4a6d-9b5d-e693e890d4e0", bgColor: "F9FF9F", bgBtnColor: "FFFFFF", bgBtnHoverColor: "000000", textColor: "000000", \xe2\x80\xa6}\ndefaultStyles: null\nemail: "nata@email.edu"\nfirstName: "Nata"\nid: "d683a6bb-383e-4cf1-943a-05b3da4e5cc3"\nlastName: "Vache"\nsocialNetwork: {nextToken: null} -- WANT THIS TO INCLUDE ACTUAL INFORMATION ABOUT SOCIAL NETWORKS CONNECTED TO THIS USER, THE …
Run Code Online (Sandbox Code Playgroud) amazon-web-services amplifyjs graphql-js aws-amplify graphql-schema
是否有可能在 graphql-ruby 模式中将 Hash 定义为 Type 字段?在我的数据结构中有一个多语言字符串类型,它由作为键的语言代码和相应的文本组成。目前提供了 2 种语言,例如:
{
"en" : "hello",
"de" : "hallo"
}
Run Code Online (Sandbox Code Playgroud)
所以构建这样的类型就足够了:
{
"en" : "hello",
"de" : "hallo"
}
Run Code Online (Sandbox Code Playgroud)
提供字符串到字符串映射的类型如何?例如,相应的打字稿界面如下所示:
title: {
[language: string]: string;
}
Run Code Online (Sandbox Code Playgroud)
更进一步,就像一个递归节点:
export interface NodeDescription {
name: string
children?: {
[childrenCategory: string]: NodeDescription[];
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在一个字段中使用它作为 graphql-ruby 模式中的 Types::NodeDescriptionType ?
graphql ×4
amplifyjs ×1
aws-amplify ×1
graphql-java ×1
graphql-js ×1
graphql-ruby ×1
keystonejs ×1
node.js ×1
ruby ×1