嗨,我试图在我的https://www.graph.cool/ db 上写一个带有变异的数据.我的项目是一个React web-app,我使用Apollo作为graphql客户端和graphql-tag npm包作为模板文字解析器.
问题是我不知道如何使用嵌套数据为正确的变异安排gql模板字符串.我的架构看起来像这样,例如,注意"公司"类型的字段"地址"是"地址"对象类型的数组.
type Company {
name: String!
website: String
Owner: User
Addresses: [Addresses]
}
type User {
name: String!
email: String
}
type Address {
street: String!
city: String!
country: String
contacts: [Contact]
}
type Contact {
name: String
email: String
phone: String
}
Run Code Online (Sandbox Code Playgroud)
例如,我想在一个突变中同时创建一个新公司,它的新所有者和多个地址.对于我需要创建新联系人的地址.
我有以下GraphQL架构.它Books和Authors一个多对多的关系.如何为现有作者创建新的Book变异?
模式
type Author implements Node {
books: [Book!]! @relation(name: "BookAuthors")
createdAt: DateTime!
id: ID! @isUnique
name: String!
updatedAt: DateTime!
}
type Book implements Node {
authors: [Author!]! @relation(name: "BookAuthors")
createdAt: DateTime!
id: ID! @isUnique
title: String!
updatedAt: DateTime!
}
Run Code Online (Sandbox Code Playgroud)
突变
mutation CreateBook($title: String!, $authors: [Author!]) {
createBook(
title: $title,
authors: $authors,
) {
id
title
}
}
Run Code Online (Sandbox Code Playgroud)
变量
{
"title": "Ryans Book",
"authors": ["cj5xti3kk0v080160yhwrbdw1"]
}
Run Code Online (Sandbox Code Playgroud) 我需要一些帮助来弄清楚订阅和实时更新的一般方法是什么。我有一个 React Native 应用程序,并使用 Apollo 和 Graphcool 服务作为后端。
在某些情况下,查看应用程序的用户会收到推送通知,告知某些内容已发生更改。当然,屏幕数据也应该更新。订阅显然是这项工作的候选者,我基本上让它发挥了作用。
我有一个像这样的订阅,它本身工作得很好(用于在谷歌地图上定位玩家头像)。
subscription PlayerMap($gameId: ID) {
Game(filter: { mutation_in: [CREATED, UPDATED], node: { id: $gameId } }) {
node {
players {
id
character {
id
name
}
user {
id
latitude
longitude
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后有一个不同的应用程序屏幕createPlayer与refetchQueriesApollo 一起执行突变(为了简单起见),它运行此查询来更新内容。
query GameCharacters($gameId: ID!) {
Game(id: $gameId) {
players {
id
character {
id
name
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当此操作完成时,订阅查询(在另一个屏幕上仍然处于活动状态)也会更新,但由于某种原因,对象Game中缺少整个节点data。
为了处理订阅,我有一个这样的组件。
class Subscriber extends Component<void, …Run Code Online (Sandbox Code Playgroud) 我正在关注 https://www.graph.cool/docs/1.0/quickstart/backend/typescript/typescript-rohd6ipoo4 for graphcool 并且我收到错误
{
"errors": [
{
"code": 3016,
"requestId": "api:api:cjc7gf91e002v0180uq2hqace",
"message": "Project not found: 'my-app@dev'"
}]}
Run Code Online (Sandbox Code Playgroud)
用于查询和变异。我是 graphcool 的新手,所以不知道为什么会这样。我正在按照上述链接中提供的步骤进行操作。
Graphql 服务器:
const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
context: req => ({
...req,
db: new Graphcool({
endpoint: 'http://localhost:60000/my-app/dev',
secret: 'mysecret123',
}),
}),
})
$ graphcool info
Service Name: my-app
dev (cluster: `local`)
HTTP: http://localhost:60000/my-app/dev
Websocket: ws://localhost:60000/my-app/dev
Run Code Online (Sandbox Code Playgroud) 我有一个名为Student的模型,想过滤掉那些物理和化学成绩相同的学生。学生模式如下。
type Student @model {
name: String!
physicsMarks: Int!
chemistryMarks: Int!
createdAt: DateTime!
id: ID! @isUnique
updatedAt: DateTime!
}
Run Code Online (Sandbox Code Playgroud)
如果我们将值作为参数传递,我们可以将字段与查询过滤器中的值进行比较,但是如何在查询时比较同一节点的两个字段?
这是我想编写的缺少过滤器的查询。
query{
allStudents(
filter:{//??//}){
id
name
}
}
Run Code Online (Sandbox Code Playgroud)
我们可以使用查询来处理这种情况吗?或者我们将不得不为这种情况编写解析器函数。
注意:- 我使用 GraphCool 的界面来定义架构、权限、解析器功能等。
我已经用这个将图像文件上传到API(Graphcool),并且一切正常:
fileUpload(file) {
let data = new FormData();
data.append('data', file);
axios
.post(`https://api.graph.cool/file/v1/MY-PROJECTID`, data, {
headers: {
'Content-Type': 'multipart/form-data',
},
})
.then(res => {
console.log(res)
});
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,文件是从 <input type="file" />
但是现在我正在使用React Avatar Editor来允许用户裁剪图像并确保它们是正方形的:https : //github.com/mosch/react-avatar-editor
当您从React Avatar Editor访问图像时,它以数据URL的形式出现(通过Canvas.toDataURL())。
如何使用Axios上传数据URL?我是否需要先将图像转换为浏览器内存中的实际“文件”?
我正在使用Graph.cool graphql作为服务,我想知道如何对集合进行批量更新,类似于SQL更新.
在我的情况下,我需要在我的数据库的imageUrl列中更新url的后缀.我需要将{someid} _sm.jpg换成{someid} _lg.jpg
我如何使用graphql变异做到这一点?我不想再次重新加载整个数据集,并且正在寻找一种不需要使用graphql客户端手动整理整个列表的方法.
mutation {
updatePost() // what goes here?
}
Run Code Online (Sandbox Code Playgroud) 我已经按照https://www.graph.cool/的步骤设置了“介绍项目” 。在项目的权限部分,我可以查看和编辑以下权限Posts:
单击显示Everyone可以Edit Data张贴的行时,将出现一个对话框。我可以在其中编辑权限,以便只有经过身份验证的用户才能编辑帖子:
但是,如何制定规则,使用户只能编辑自己的帖子,而不能编辑其他用户创建的帖子?
我正在尝试使用Graphcool为我们的产品设计后端.我们已经拥有该产品的域模型.
我面临的问题是非标量属性,我被迫使用@relation(太双向关系).
帮我设计以下案例
# projectId: cj4dsyc7ur8cc0142s3hesy1r
# version: 2
type File implements Node {
contentType: String!
createdAt: DateTime!
id: ID! @isUnique
name: String!
secret: String! @isUnique
size: Int!
updatedAt: DateTime!
url: String! @isUnique
}
type User implements Node {
createdAt: DateTime!
email: String @isUnique
id: ID! @isUnique
password: String
updatedAt: DateTime!
}
type Record implements Node {
createdAt: DateTime!
id: ID! @isUnique
name: String!
description: String!
createdBy: User!
modifiedBy: User!
}
Run Code Online (Sandbox Code Playgroud)
为此,我得到了错误
Errors
createdBy: The relation field `createdBy` must specify …Run Code Online (Sandbox Code Playgroud) 我如何使用Delphi界面Graph.cool?
我想建立一个Win32 / Win64 / OSX客户端
https://Graph.cool/具有GraphQL(REST)API端点。
示例:https: //api.graph.cool/simple/v1/ENDPOINT
使用FaceBook GraphQL实现GraphQL的已知示例位于:http ://docwiki.embarcadero.com/RADStudio/Tokyo/en/REST_Client_Library
我有一个示例查询:
mutation {
createUser(
authProvider: {
email: { email: "hello@hello.com", password: "hello"
}}
)
{
id
}
}
Run Code Online (Sandbox Code Playgroud)
创建一个用户帐户。
我尝试使用TRestClient,但是似乎没有办法放置非结构化的字符串查询。
DFM的片段:
var
RESTRequest1: TRESTRequest;
RESTRequest1 := TRESTRequest.Create(Self);
RESTRequest1.Name := 'RESTRequest1';
RESTRequest1.AcceptEncoding := ' ';
RESTRequest1.Client := RESTClient1;
RESTRequest1.Method := rmPOST;
with RESTRequest1.Params.Add do begin
name := 'query';
Options := [poAutoCreated];
Value := '{ "query": "mutation { createUser(authProvider: { email: { email: \"hello@hello\", password: \"hello\" …Run Code Online (Sandbox Code Playgroud) 我在名为“列表”的模型中创建了一个字段。这里的字段是“类别”。这设置为一些值的枚举(下面的屏幕截图)。graphql是否允许查询以获取枚举列表?

我在我的Mac上本地安装graphcool,我认为已经好了:
$ sudo npm install -g graphcool
npm WARN deprecated jsonstream@1.0.3: use JSONStream instead
npm WARN deprecated graceful-fs@3.0.11: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
/usr/local/bin/graphcool-framework -> /usr/local/lib/node_modules/graphcool/dist/index.js
/usr/local/bin/gcf -> /usr/local/lib/node_modules/graphcool/dist/index.js
+ graphcool@0.11.4
updated 1 package in 7.251s
Run Code Online (Sandbox Code Playgroud)
但似乎没有认识到graphcool:
$ graphcool init server
-bash: graphcool: command not found
Run Code Online (Sandbox Code Playgroud)
我得到了同样的错误graphcool init.
谁能帮我?
graphcool ×12
graphql ×8
react-apollo ×2
axios ×1
delphi ×1
javascript ×1
prisma ×1
reactjs ×1
todataurl ×1