Я хочу добавить фреймворк apollo в свой проект iOS. Я следую документация, но не могу его построить.
Я собираю его и получаю следующую ошибку:
Мой файл schema.grapqhl выглядит примерно так:
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: сгенерировать --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 неверен.
your
schema.graphqlfile is a representation of your schema in the schema definition language, not a query document. apollo ios expects you to define the queries your app uses in.graphqlfiles, so it can generate code from them. these are the queries the client sends to the server, similar to what you would put in graphiql for example... queries need to be named. so if you put this in a
.graphqlfile:
query AllQuestions {
queries {
text
}
}
that will generate a
AllQuestionsQueryswift class that you can pass toclient.fetch(query:)and it will also generate result types with the exact fields you requested (edited) so you can accesstext, but notactivefor example so in contrast to global model types, query-specific types give you complete type safety for your data fetching
как ответил @Sergej Birklin, я хотел бы поделиться с вами еще одним вопросом -
Profile.graphql
query MyProfile{
player {
me {
id
secret
name
email
state
country
timezone
picture
pictureType
audio
rank
}
}
}
Поскольку мы просто запрашиваем информацию о моем профиле (где я указан как тип игрок), запрос вернет информацию, которая мне нужна, например, мой идентификатор, имя, адрес электронной почты, состояние и т. д.
as you state that it will create MyProfileQuery
Надеюсь, это поможет вам ??
#swith #GraphQL #iOS
Эта статья вам тоже поможет Сопоставление типов GraphQL с Swift