Comments (8)
Hi I cannot reproduce the issue you mentioned. Did you try the latest version of CLI? If the issue still remains in codegen, could you provide your codegen target languange?(can be found in .graphqlconfig.yml
, codegenTarget
field)
from amplify-codegen.
Hi @AaronZyLee
well, for a production schema it logs about 5000 errors:
So the solution you suggested doesn't look to be usable in this case.
I'm not sure why are you saying that it's a customized situation.
I believe that the codegen generation approach should be redesigned.
Also, why it's not allowing just TypeScript types generation w/o the queries generation? There should not be any problem with generating types for schema.
from amplify-codegen.
Here's the data for reproduction: https://drive.google.com/drive/folders/1wAPAIm1W1ws12SyjQVDe3Z6IrcykNi9n?usp=sharing
And here's the repro video: https://drive.google.com/file/d/1BphJphcHM4C1qqiKQUjdqYuFh_tRfs8j/view?usp=sharing
The GraphQL schema is simple:
type Document implements Object {
id: ID
index: Int
}
interface Object {
id: ID
}
type Place implements Object {
id: ID
index: String
}
type Query {
obj: Object
}
schema {
query: Query
}
from amplify-codegen.
So, looks like the problem is in the generated query. This is the generated queries.ts
contents:
export const obj = /* GraphQL */ `
query Obj {
obj {
id
... on Document {
index
}
... on Place {
index
}
}
}
`;
As you can see, the query contains index
field for both types (Document
and Place
), and this query is indeed invalid because index
has different types.
In theory, it's possible to change the existing GraphQL API to workaround this issue, but in practice, it's not the way to go.
Any ideas? Is it a known Amplify codegen limitation?
from amplify-codegen.
@rzinnatullin It is not the limitation for amplify codegen but the graphql-js. The error is thrown by the schema validation of graphql
. I also notice a similar github issue. I suggest to use the alias as the following instead if you have two different types of the same field name. The queries.ts
generated by doc-gen just serves as a starting point. The naming for alias is much flexible and it is better to change the query manually to use your own alias names.
export const obj = /* GraphQL */ `
query Obj {
obj {
id
... on Document {
docIdx: index
}
... on Place {
placeIdx: index
}
}
}
`;
from amplify-codegen.
@AaronZyLee Thanks. There's no problem with graphql-js
, it does its work perfectly fine. The problem is with the codegen itself - it generates an invalid query. My expectation from the codegen is that it just gives me a valid output.
from amplify-codegen.
@rzinnatullin I agree. The doc-gen is much like a starting point and cannot handle some customized situations. The solution to this is to add the alias names where there is a conflict and since the alias names are much random and customized we recommend to modify the queries manually as I mentioned in the last comment. I will close this issue but feel free to reopen it if the problem is not resolved.
from amplify-codegen.
We are facing exactly the same issues, as @rzinnatullin said, solution proposed by @AaronZyLee doesn't make sense at all.
Can this issue be reopened since the issue still exists in the latest version? IMO it should either automatically add those aliases or be able to skip directly to just types generation
from amplify-codegen.
Related Issues (20)
- Amplify CLI 12.10 - No queries found to generate types for HOT 6
- Missing Types HOT 2
- Amplify codegen doesn't support namespace queries/mutations HOT 3
- allow customizing generated graphql
- Allow saving patch changes to generated code HOT 2
- Incorrect __typename Generation on Custom Type HOT 1
- Angular code generation for v6 amplify HOT 5
- Cannot generate Models from GraphQL schema HOT 2
- Cannot use 'in' operator to search for 'name' in amplify codegen [UPDATE] HOT 6
- Gen 2 codegen generates wrong getters for "id" field in a model HOT 3
- Amplify codegen and EOENT model-introspection.js/schema.js HOT 3
- Types not generated for non null return types for mutations HOT 1
- Build fail on unknown type from GraphQL Scheme HOT 4
- [WARN] 16:19.312 DataStore - Skipping incoming subscription. HOT 7
- Mutations break after aws-amplify/cli update: "input contains a field that is not defined" HOT 10
- Unable to generate operations.graphql HOT 5
- unnecessary_non_null_assertion for `updatedAt` and `createdAt` in `toString()` from dart generator
- Amplify Configure Codegen FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory HOT 3
- Gen2 Data allow.ownersDefinedIn("owners") does not generate "owners" field on Swift model HOT 6
- how to fix graphql query can't get full result? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from amplify-codegen.