简体   繁体   中英

API.swift file not update : Apollo GraphQL iOS

I am using GraphQL API with iOS project.my.graphql file is,

mutation SigninQuery($email: String! , $password: String!) {
    signin(email: $email, password: $password) {
        result {
            token
            firstName
            lastName
            profileImage
        }
    }
}

and my files are located in the following order,

Project

  • ->appDelegate
  • ->info.plist
  • ->schema.json
  • -->Graphql[Folder]

  • ->API.swift

  • ->ApiFile.graphql

My API.swift file still exist only with header

import Apollo

. Anyone can you please help me to findout the solution

If you correct initialized the apollo client, then you won't have such a problem. I installed Apollo using Swift packages . I did following steps:

  1. Hierarchy

在此处输入图片说明

  1. Script to generate API.swift (pay attention on folder to generate and name of schema. In my case, folder is GraphQL and name is tetsTet ):
 DERIVED_DATA_CANDIDATE="${BUILD_ROOT}" while ! [ -d "${DERIVED_DATA_CANDIDATE}/SourcePackages" ]; do if [ "${DERIVED_DATA_CANDIDATE}" = / ]; then echo >&2 "error: Unable to locate SourcePackages directory from BUILD_ROOT: '${BUILD_ROOT}'" exit 1 fi DERIVED_DATA_CANDIDATE="$(dirname "${DERIVED_DATA_CANDIDATE}")" done # Grab a reference to the directory where scripts are checked out SCRIPT_PATH="${DERIVED_DATA_CANDIDATE}/SourcePackages/checkouts/apollo-ios/scripts" if [ -z "${SCRIPT_PATH}" ]; then echo >&2 "error: Couldn't find the CLI script in your checked out SPM packages; make sure to add the framework to your project." exit 1 fi cd "${SRCROOT}/${TARGET_NAME}/GraphQL" "${SCRIPT_PATH}"/run-bundled-codegen.sh codegen:generate --target=swift --includes=./**/*.graphql --localSchemaFile="tetsTets.json" API.swift
  1. Drag the generated API.swift file to your folder

uncheck the "Copy Files If Needed" checkbox

I'm trying to build my project with autogenerated code

apollo codegen:generate --target=swift --includes=CourseQuery.graphql --localSchemaFile="schema.json" API.swift

The file API.swift is then generated and added to Xcode project.

Building the project I get this error

Cannot find type 'GraphQLQuery' in scope

This is how the class is defined

public final class CourseQuery: GraphQLQuery

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM