* Which Category is your question related to? *
GraphQL transformer codegen
* Provide additional details e.g. code snippets *
I'm adding a fragment in a custom GraphQL query file. For example:
fragment SheetParts on Sheet {
id,
name,
bpm,
}
query ListItemPage($id: ID!) {
getList(id: $id) {
name,
sheets {
items {
...SheetParts
}
}
}
}
query MyLibraryPage($limit: Int, $nextToken: String) {
listSheets(limit: $limit, nextToken: $nextToken) {
nextToken,
items {
...SheetParts
}
}
}
Codegen gracefully generates SheetPartsFragment into my API, but when requesting the qery through the generated API, I get this error:
core.js:15724 ERROR Error: Uncaught (in promise): Object: {"data":null,"errors":[{"path":null,"locations":[{"line":9,"column":9,"sourceName":null}],"message":"Validation error of type UndefinedFragment: Undefined fragment SheetParts @ 'getList/sheets/items'"}]}
Am I missing something?
Thanks
This seems a bug in the angular service generation. The fragment definition is missing in the generated API queries. It works if I manually edit the generated service and add the missing fragment after the query.
@brunostuani Currently Amplify Codegen does not support fragments. Marking this as an enhancement.
As my GraphQL schema is getting bigger, I was looking for a similar solution and just discovered fragments.
This would be a very nice addition to the CLI!
Is there a way to make it work by bypassing the codegen part, or are fragments simply not usable on Amplify ?
Here is the alternative I was considering (a client query builder): https://github.com/atulmy/gql-query-builder
But having this handled server-side would be much better.
I have been using a hacky implementation for some time now and finally managed to assemble it as a plugin https://github.com/artemkloko/amplify-graphql-fragments-generator
It supports only TypeScript and is not for production. Still would be nice if someone could test it on a playground project or comment on the strategy itself.
@artemkloko I'm really liking the look of that library! I have also created your first issue! (sorry!) - https://github.com/artemkloko/amplify-graphql-fragments-generator/issues/1
let me know if you need any help with the issue 馃憤
Most helpful comment
As my GraphQL schema is getting bigger, I was looking for a similar solution and just discovered fragments.
This would be a very nice addition to the CLI!
Is there a way to make it work by bypassing the codegen part, or are fragments simply not usable on Amplify ?
Here is the alternative I was considering (a client query builder): https://github.com/atulmy/gql-query-builder
But having this handled server-side would be much better.