安装GraphQL iOS框架
我想将apollo框架添加到我的iOS项目中。我正在跟踪,但无法构建它安装GraphQL iOS框架,ios,graphql,apollo,Ios,Graphql,Apollo,我想将apollo框架添加到我的iOS项目中。我正在跟踪,但无法构建它 我通过Cocoapod安装阿波罗 我将代码生成构建步骤添加到目标中(将其置于编译源代码之上…) 我通过apollo schema下载模式:download--endpoint=schema.json。我将schema.json文件添加到项目的根目录中 我构建它并得到以下错误: Warning: apollo update available from 1.2.0 to 1.7.0 .../schema.graphql: Th
Warning: apollo update available from 1.2.0 to 1.7.0
.../schema.graphql: The Query definition is not executable.
.../schema.graphql: The Mutation definition is not executable.
.../schema.graphql: The Subscription definition is not executable.
.../schema.graphql: The Question definition is not executable.
... some more ...
:heavy_check_mark: Scanning for GraphQL queries (1 found)
:heavy_check_mark: Loading GraphQL schema
:heavy_check_mark: Parsing GraphQL schema
:heavy_multiplication_x: Generating query files with 'swift' target
→ Validation of GraphQL query document failed
ToolError: Validation of GraphQL query document failed
at Object.validateQueryDocument
....
- apollo@1.2.0
在20.385s中增加了416个包
++exec/Users/PATH/node_modules/.bin/apollo-codegen:generate--querys=--schema=schema.json-API.swift
›警告:阿波罗更新版本从1.2.0版到1.7.0版
›错误:标志--查询需要一个值
命令/bin/sh失败,退出代码为2
type Query {
""" User """
users: [User!]!
user(username: String!): User
""" Question """
questions: [Question!]!
question(id: Int!): Question
}
type Mutation {
""" User """
createUser(username: String!): User
updateUser(username: String!, newUsername: String!): [Int!]!
deleteUser(username: String!): Int!
""" Question """
createQuestion(text: String!, category: Int!, active: Boolean!):
Question
updateQuestion(id: Int!, text: String!, category: Int!, active: Boolean!): [Int!]!
deleteQuestion(id: Int!): Int!
}
type Subscription {
answerAdded: Answer
}
type Question {
id: Int!
text: String!
categoryId: QuestionCategory!
active: Boolean!
createdAt: String!
updatedAt: String!
}
......
查询参数似乎没有输入:
apollo codegen:generate--queries=--schema=schema.json API.swift
如果我自己通过终端试一试
apollo codegen:generate --queries=schema.graphql --schema=schema.json API.swift
我得到以下错误:
Warning: apollo update available from 1.2.0 to 1.7.0
.../schema.graphql: The Query definition is not executable.
.../schema.graphql: The Mutation definition is not executable.
.../schema.graphql: The Subscription definition is not executable.
.../schema.graphql: The Question definition is not executable.
... some more ...
:heavy_check_mark: Scanning for GraphQL queries (1 found)
:heavy_check_mark: Loading GraphQL schema
:heavy_check_mark: Parsing GraphQL schema
:heavy_multiplication_x: Generating query files with 'swift' target
→ Validation of GraphQL query document failed
ToolError: Validation of GraphQL query document failed
at Object.validateQueryDocument
....
你能帮我找出为什么我不能建这个项目吗?是因为我的schema.graphl文件出错吗?多亏了打开的Apollo Slack iOS频道,我才解决了这个问题
问题是我的schema.graphql文件是错误的
您的schema.graphql
文件是模式定义语言中的模式表示,而不是查询文档。apollo ios希望您在.graphql
文件中定义应用程序使用的查询,以便它可以从中生成代码。
这些是客户机发送到服务器的查询,类似于您在graphiql中的查询
。。。查询需要命名。因此,如果将其放入.graphql
文件中:
这将生成一个AllQuestionsQuery
swift类,您可以将该类传递给client.fetch(查询:)
它还将生成带有您请求(编辑)的确切字段的结果类型
例如,您可以访问文本
,但不能访问活动
因此,与全局模型类型相比,查询特定类型为数据获取提供了完整的类型安全性
正如@Sergej Birklin所回答的,我想与您分享另一个问题- Profile.graphql
query MyProfile{
player {
me {
id
secret
name
email
state
country
timezone
picture
pictureType
audio
rank
}
}
}
由于我们只是查询我的个人资料信息(其中我是玩家类型),查询将返回我所需的信息,如我的ID、姓名、电子邮件、状态等
正如您所说,它将创建MyProfileQuery
希望这将帮助你,这篇文章也将帮助你