GraphQL JSON模式到Apollo客户端模式



我有一个JSON模式文件,看起来像这个

{
"data": {
"__schema": {
"queryType": { "name": "Query" },
"mutationType": { "name": "Mutation" },
"subscriptionType": null,
"types": [
{
"kind": "OBJECT",
"name": "Query",
"description": "",
"fields": [
{
"name": "planningSearch",
"description": "",
"args": [
{
"name": "search",
"description": "",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "PlanningSearchInput",
"ofType": null
}

然而,这在我的Android工作室项目中不起作用,我正在遵循Apollo Kotlin GraphQL教程,他们正在使用并告诉你添加到项目中的模式如下:

type Query {
launches("The number of results to show. Must be >= 1. Default = 20" pageSize: Int, "If you add a cursor here, it will only return results _after_ this cursor" after: String): LaunchConnection!
launch(id: ID!): Launch
me: User
totalTripsBooked: Int
}

type LaunchConnection {
cursor: String!
hasMore: Boolean!
launches: [Launch]!
}
type Launch {
id: ID!
site: String
mission: Mission
rocket: Rocket
isBooked: Boolean!
}
type Mission {
name: String
missionPatch(size: PatchSize): String
}

type User {
id: ID!
email: String!
profileImage: String
trips: [Launch]!
token: String
}
type Mutation {
bookTrips(launchIds: [ID]!): TripUpdateResponse!
cancelTrip(launchId: ID!): TripUpdateResponse!
login(email: String): User
}
type TripUpdateResponse {
success: Boolean!
message: String
launches: [Launch]
}


schema {
query: Query
mutation: Mutation
subscription: Subscription
}

如何将JSON模式转换为预期模式?

您所期望的是称为GraphQLSDL模式格式,并且有一些npm工具,如GraphQL-inspectrationjson-to-SDL、GraphQL-json-to-SDL或一些在线网站-json2sdl可以很容易地做到这一点。

最新更新