Giter VIP home page Giter VIP logo

Comments (8)

AaronZyLee avatar AaronZyLee commented on August 17, 2024 2

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.

rzinnatullin avatar rzinnatullin commented on August 17, 2024 2

Hi @AaronZyLee
well, for a production schema it logs about 5000 errors:
image

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.
image

from amplify-codegen.

rzinnatullin avatar rzinnatullin commented on August 17, 2024

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.

rzinnatullin avatar rzinnatullin commented on August 17, 2024

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.

AaronZyLee avatar AaronZyLee commented on August 17, 2024

@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.

rzinnatullin avatar rzinnatullin commented on August 17, 2024

@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.

AaronZyLee avatar AaronZyLee commented on August 17, 2024

@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.

PatrykMilewski avatar PatrykMilewski commented on August 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.