Apollo-ios: Cannot read property 'getMutationType' of undefined

Created on 22 Jan 2019  ·  27Comments  ·  Source: apollographql/apollo-ios

Now using node v8.15.0 (npm v6.4.1)
 ›   Warning: apollo update available from 1.9.2 to 2.1.8
++ npx --no-install apollo codegen:generate '--queries=./services/graphQl/CreateNewPost.graphql
./services/graphQl/DeletePost.graphql
./services/graphQl/GetComments.graphql
./services/graphQl/PostComments.graphql
./services/graphQl/UpdatePost.graphql' --schema=schema.json API.swift
›   Warning: apollo update available from 1.9.2 to 2.1.8
[12:43:55] Loading Apollo config [started]
[12:43:55] Loading Apollo config [completed]
[12:43:55] Resolving GraphQL document sets and dependencies [started]
[12:43:55] Scanning for GraphQL queries (5 found) [title changed]
[12:43:55] Scanning for GraphQL queries (5 found) [completed]
[12:43:55] Generating query files [started]
[12:43:55] Generating query files with 'swift' target [title changed]
[12:43:55] Generating query files with 'swift' target [failed]
[12:43:55] → Cannot read property 'getMutationType' of undefined
TypeError: Cannot read property 'getMutationType' of undefined

Getting this error
i researched a bit about it and i gone through many steps as per mentioned in internet

  1. Moving schema.json file into the place where AppDelegate lies
  2. sudo npm install --save graphql Updating graphQl dependencies
  3. And i upgraded my apollo to using sudo npm install -g [email protected] and i checked it apollo/2.1.8 darwin-x64 node-v10.14.2 (checked from the project root folder)
  4. sudo npm install -g apollo upgraded into latest apollo 2.3.0
  5. Also tried running passing --passthroughCustomScalars:
    $APOLLO_FRAMEWORK_PATH/check-and-run-apollo-cli.sh codegen:generate --queries="$(find . -name '*.graphql')" --passthroughCustomScalars --schema=schema.json API.swift

even all these steps i still getting the error , i am currently using the script from the apollo graphql ios documentation , and the version i am using is 0.9.5

codegen

Most helpful comment

Hi all, I think I've same issue here:
Apollo pod version: 0.9.5

Now using node v8.15.0 (npm v6.4.1)
› Warning: apollo update available from 1.9.2 to 2.5.1.
++ npx --no-install apollo codegen:generate --queries=./Test.graphql --schema=schema.json API.swift
› Warning: apollo update available from 1.9.2 to 2.5.1.
[17:37:18] Loading Apollo config [started]
[17:37:18] Loading Apollo config [completed]
[17:37:18] Resolving GraphQL document sets and dependencies [started]
[17:37:18] Scanning for GraphQL queries (1 found) [title changed]
[17:37:18] Scanning for GraphQL queries (1 found) [completed]
[17:37:18] Generating query files [started]
[17:37:18] Generating query files with 'swift' target [title changed]
Test.graphql:3: error: Cannot query field "nodes" on type "Query".
[17:37:18] Generating query files with 'swift' target [failed]
[17:37:18] → Validation of GraphQL query document failed
ToolError: Validation of GraphQL query document failed
at Object.validateQueryDocument (~/Desktop/ResearchDevelop/testApollo/node_modules/apollo/lib/validation.js:31:15)
at Object.generate [as default] (~/Desktop/ResearchDevelop/testApollo/node_modules/apollo/lib/generate.js:19:18)
at Task.task (~/Desktop/ResearchDevelop/testApollo/node_modules/apollo/lib/commands/codegen/generate.js:98:64)
at Promise.resolve.then.then.skipped (~/Desktop/ResearchDevelop/testApollo/node_modules/listr/lib/task.js:167:30)
at

Help :) ?

All 27 comments

Is that message followed with a stack trace?

I'm having the same issue

›   Warning: apollo update available from 1.9.2 to 2.3.1
++ npx --no-install apollo codegen:generate '--queries=./Server Communication/Auth.graphql' --schema=schema.json API.swift
 ›   Warning: apollo update available from 1.9.2 to 2.3.1
[17:12:04] Loading Apollo config [started]
[17:12:04] Loading Apollo config [completed]
[17:12:04] Resolving GraphQL document sets and dependencies [started]
[17:12:04] Scanning for GraphQL queries (1 found) [title changed]
[17:12:04] Scanning for GraphQL queries (1 found) [completed]
[17:12:04] Generating query files [started]
[17:12:04] Generating query files with 'swift' target [title changed]
[17:12:04] Generating query files with 'swift' target [failed]
[17:12:04] → Cannot read property 'getMutationType' of undefined
TypeError: Cannot read property 'getMutationType' of undefined

I've tried the same steps @Eldhopj stated in his comment, but the error is still here. One thing, I have this method in my .graphql file
mutation { authenticate(email: "email", password:"pass") { token } }. If remove token from it, it builds without errors but API.swift is not updated.

We haven't been able to reproduce this, which makes it hard to know where to look. Would anyone be able to share a project that exhibits this behavior?

Is that message followed with a stack trace?

Yes this stack trace is from XCode 10

Im getting the same issues after I upgrade my apollo version, is this solve already?

@solimanjuanito No, we need a reproduction, see above:
https://github.com/apollographql/apollo-ios/issues/440#issuecomment-459091283

@solimanjuanito No, we need a reproduction, see above:
#440 (comment)

Update :
When i downgrade to apollo codegen and to apollo 0.7.0 there is no issue , but the problem is that i cant able to use graphQl subscription on 0.7.0
Note : I am currently running Xcode 10 on Macos highSierra

I had the same issue with "Cannot read property 'getMutationType' of undefined" on Xcode 10. For me, the solution was to install Apollo CLI version 1.8.3 and last version of Apollo cocoa pods and check schema.json path, because when the schema file isn't inside project there is no error about missing schema but the error with getMutationType. @martijnwalraven maybe you can try this to reproduce the error with this (versions Apollo CLI 1.8.3 with last Apollo cocoa pods 0.9.3, "Generate Apollo GraphQL API" included inside Build Phases, also first .graphql file inside the project, but wrong schema path or just no schema.json file). It looks for me that this error message is just a problem with no checking schema file inside project but trying to generate mutation from a .graphql file, and it can't get the type from it. I hope to help you guys.
I'm still having the warning about version 2.5.1 but if I install it, the script installs me previous version inside project - I don't get this.

Hi all, I think I've same issue here:
Apollo pod version: 0.9.5

Now using node v8.15.0 (npm v6.4.1)
› Warning: apollo update available from 1.9.2 to 2.5.1.
++ npx --no-install apollo codegen:generate --queries=./Test.graphql --schema=schema.json API.swift
› Warning: apollo update available from 1.9.2 to 2.5.1.
[17:37:18] Loading Apollo config [started]
[17:37:18] Loading Apollo config [completed]
[17:37:18] Resolving GraphQL document sets and dependencies [started]
[17:37:18] Scanning for GraphQL queries (1 found) [title changed]
[17:37:18] Scanning for GraphQL queries (1 found) [completed]
[17:37:18] Generating query files [started]
[17:37:18] Generating query files with 'swift' target [title changed]
Test.graphql:3: error: Cannot query field "nodes" on type "Query".
[17:37:18] Generating query files with 'swift' target [failed]
[17:37:18] → Validation of GraphQL query document failed
ToolError: Validation of GraphQL query document failed
at Object.validateQueryDocument (~/Desktop/ResearchDevelop/testApollo/node_modules/apollo/lib/validation.js:31:15)
at Object.generate [as default] (~/Desktop/ResearchDevelop/testApollo/node_modules/apollo/lib/generate.js:19:18)
at Task.task (~/Desktop/ResearchDevelop/testApollo/node_modules/apollo/lib/commands/codegen/generate.js:98:64)
at Promise.resolve.then.then.skipped (~/Desktop/ResearchDevelop/testApollo/node_modules/listr/lib/task.js:167:30)
at

Help :) ?

Same problem with my team. Anybody find anything out?

Hey, still having this issue? @JinkProject

I removed the POD and wrote simple HTTP calls and with that parameters with the query and it’s working fine

Did you guys find a version that solved this?

Same issue, somebody found solution?

Same issue here :-(

@gmoraleda Or anyone else - is anyone willing to share either here or by email a query which is causing this? It'd be most helpful if you can show the before and after of a query that was working but then started freaking out on this issue.

Hi @designatednerd !
I created a sample project to test Apollo. I'm using the mutations/queries from our Android app (already working with Apollo): https://github.com/ios-cluno/GraphQL
So the project is pretty much empty. Was created using Xcode11-beta2.

OK cool. One thing that jumped out at me just taking a quick look: Deal.graphql is not indented the way the other queries and mutations are. If you update the indentation there, does the CLI stop freaking out?

I put all the graphql files through http://toolbox.sangria-graphql.org/format but the issue remains the same:

 ›   Warning: apollo update available from 1.9.2 to 2.14.1.
++ npx --no-install apollo codegen:generate '--queries=./GraphQL/UploadOtherProofOfIncome.graphql
./GraphQL/RequestUrl.graphql
./GraphQL/User.graphql
./GraphQL/UploadDriversLicense.graphql
./GraphQL/Deal.graphql
./GraphQL/SchufaResult.graphql
./GraphQL/IdentityProof.graphql
./GraphQL/Signing.graphql
./GraphQL/BankDetails.graphql
./GraphQL/UploadProofOfIncome.graphql' --schema=schema.json API.swift
 ›   Warning: apollo update available from 1.9.2 to 2.14.1.
[15:19:53] Loading Apollo config [started]
[15:19:53] Loading Apollo config [completed]
[15:19:53] Resolving GraphQL document sets and dependencies [started]
[15:19:53] Scanning for GraphQL queries (10 found) [title changed]
[15:19:53] Scanning for GraphQL queries (10 found) [completed]
[15:19:53] Generating query files [started]
[15:19:53] Generating query files with 'swift' target [title changed]
[15:19:53] Generating query files with 'swift' target [failed]
[15:19:53] → Cannot read property 'getMutationType' of undefined
TypeError: Cannot read property 'getMutationType' of undefined
    at TypeInfo.enter (~/Dev/ApolloTest/node_modules/apollo/node_modules/graphql/utilities/TypeInfo.js:144:25)
    at Object.enter (~/Dev/ApolloTest/node_modules/apollo/node_modules/graphql/language/visitor.js:363:16)
    at Object.visit (~/Dev/ApolloTest/node_modules/apollo/node_modules/graphql/language/visitor.js:254:26)
    at getValidationErrors (~/Dev/ApolloTest/node_modules/apollo/lib/validation.js:21:15)
    at Object.validateQueryDocument (~/Dev/ApolloTest/node_modules/apollo/lib/validation.js:26:30)
    at Object.generate [as default] (~/Dev/ApolloTest/node_modules/apollo/lib/generate.js:19:18)
    at Task.task (~/Dev/ApolloTest/node_modules/apollo/lib/commands/codegen/generate.js:98:64)
    at Promise.resolve.then.then.skipped (~/Dev/ApolloTest/node_modules/listr/lib/task.js:167:30)
Command PhaseScriptExecution failed with a nonzero exit code

OK! That helps at least throw that out as a possibility. Will take a look into it!

Anyone on this thread able to try with the updated codegen in 0.13.0 and get better results?

I got it working with two minor tweaks:

  1. Updated the version of apollo cli in Pods/Apollo/scripts/check-and-run-apollo-cli.sh:
    REQUIRED_APOLLO_CLI_VERSION=2.16
  2. Modified the run script:
SCRIPT_PATH="${PODS_ROOT}/Apollo/scripts"
cd "${SRCROOT}/${TARGET_NAME}" 
"${SCRIPT_PATH}"/check-and-run-apollo-cli.sh codegen:generate --target=swift --includes=./**/*.graphql --localSchemaFile="${SRCROOT}/schema.json" API.swift

With these two changes I was able to generate the API.swift file during in the build phase 👍

@gmoraleda Yes, that change on the required CLI version is included in 0.13.0, and then the change to the run script is required to use the updated CLI.

Since I haven't heard back from anyone else and it seems like upgrading to 0.13.0 should fix the problem as long as your graphQL is valid, I'm going to close this issue out. Please open a new issue if you are still having problems with this! Thank you!

@designatednerd mmm... I deintegrated the Pods and reinstalled them but the script inside was still the same (not version pinned in the Podfile). I had to manually edit the script.
Is that change released in the most current production version?

Nevertheless the run scrip suggested in the documentation had to be modified as well:
--localSchemaFile="${SRCROOT}/schema.json"
Otherwise it didn't find the schema.

I will double check that this is in the instructions, but you do need to put in a path to the schema file if it's not in the same folder as "${SRCROOT}/${TARGET_NAME}"

As for why it stayed the same version after de/re-integration, Cocoapods stopped automatically pulling updates to the master repo on pod install a while back because it almost broke Github- you may want to try running pod outdated to force an update of the spec repo, which then should make our most recent version available to you.

Wow... that was an informative article! 😅
Thanks again for your support. Now that I got it working is time to play around with Apollo.
Cheers!

Was this page helpful?
0 / 5 - 0 ratings