I'm updating from 1.10.0 to 1.17.0.
I changed the build script phase to use the new Apollo CLI.
SCHEMA_PATH="${SRCROOT}/Prima/Network/GraphQL"
SCRIPT_PATH="${PODS_ROOT}/Apollo/scripts"
"${SCRIPT_PATH}"/run-bundled-codegen.sh codegen:generate --target=swift --includes=./**/*.graphql --localSchemaFile="${SCHEMA_PATH}/schema.json" --passthroughCustomScalars --customScalarsPrefix="GraphQL" --namespace="GraphQL" GraphQL_generated.swift
When the script is executed I get the following error for all my queries and mutations:
Error: There are multiple definitions for the OPERATION_NAME operation. All operations in a project must have unique names. If generating types, only the types for the first definition found will be generated.
This is an example of a simple query:
query WebsiteAccessLinks {
websiteAccessLinks{
slug
url
}
}
which was working with Apollo 1.10.0.
How should I write queries to avoid this error?? (when removing the external name I get another error saying that unnamed queries are not supported).
To make it work I changed all operations names by adding a suffix ('Q' for queries and 'M' for mutations) to disambiguate "external" and "internal" query name.
But now, when I build I get the error:
Type does not conform to protocol 'GraphQLOperation'
again for all my queries and mutations.
The problem is that the operationName property has not been generated.
Searching previous issues I found #769 which seems to be the same problem but in my case, neither deleting build folder nor updating node to the latest version fixes the problem.
To be sure that I'm using the ApolloCLI version embedded in the Pod I completely removed the globally installed ApolloCLI from my machine.
The only hint I have is that the codegen sciriptis emitting this warning:
Warning: apollo update available from 2.19.1 to 2.20.0
but I think that is the pod script which should take care of updating the ApolloCLI.
Moreover, reading the docs, it seems that version 2.19.1 should already have the logic to generate operationName
As often occurs, after averting the mind from this problem I noticed the error (on my side)! 馃挕
When changing the build script to the new syntax I forgot to bring back a cd instruction which I used in the previous script to put the generated code file in my GraphQL directory.
Thus all the above mentioned errors were due to the fact that I actually had two distint GraphQL_generated files which, obviosly were conflicting.
@francybiga Thanks for explaining for anyone else who comes across the same problem!
Most helpful comment
As often occurs, after averting the mind from this problem I noticed the error (on my side)! 馃挕
When changing the build script to the new syntax I forgot to bring back a
cdinstruction which I used in the previous script to put the generated code file in my GraphQL directory.Thus all the above mentioned errors were due to the fact that I actually had two distint
GraphQL_generatedfiles which, obviosly were conflicting.