amplify-codegen
amplify-codegen copied to clipboard
Generated custom query for @key directive, doesn't return custom non-model types within data model
Before opening, please confirm:
- [X] I have searched for duplicate or closed issues and discussions.
- [X] I have read the guide for submitting bug reports.
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
Next.js
Amplify APIs
GraphQL API
Amplify Categories
api
Environment information
# Put output below this line
System:
OS: macOS 10.15.7
CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Memory: 59.26 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 14.16.1 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.12 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Browsers:
Chrome: 94.0.4606.81
Chrome Canary: 97.0.4667.3
Firefox: 89.0.2
Safari: 13.1.3
npmPackages:
3d-react-carousal: ^3.1.0 => 3.1.0
@ampproject/toolbox-optimizer: undefined ()
@aws-amplify/ui-react: ^1.2.19 => 1.2.19
@babel/core: undefined ()
@hookform/resolvers: ^2.5.2 => 2.8.1
@material-ui/core: ^4.11.3 => 4.12.3
@material-ui/icons: ^4.11.2 => 4.11.2
@material-ui/lab: ^4.0.0-alpha.58 => 4.0.0-alpha.60
@types/node: ^15.12.1 => 15.14.9 (16.10.2)
@types/react: ^17.0.9 => 17.0.27
amphtml-validator: undefined ()
arg: undefined ()
async-retry: undefined ()
async-sema: undefined ()
aws-amplify: ^4.3.1 => 4.3.1
bfj: undefined ()
cacache: undefined ()
cache-loader: undefined ()
ci-info: undefined ()
class-validator: 1.0.0
classnames: ^2.3.1 => 2.3.1 (2.2.6)
comment-json: undefined ()
compression: undefined ()
computed-types: 1.0.0
conf: undefined ()
content-type: undefined ()
cookie: undefined ()
css-loader: undefined ()
debug: undefined ()
devalue: undefined ()
escape-string-regexp: undefined ()
file-loader: undefined ()
find-cache-dir: undefined ()
find-up: undefined ()
fresh: undefined ()
gzip-size: undefined ()
http-proxy: undefined ()
ignore-loader: undefined ()
io-ts: 1.0.0
is-animated: undefined ()
is-docker: undefined ()
is-wsl: undefined ()
joi: 1.0.0
json5: undefined ()
jsonwebtoken: undefined ()
loader-utils: undefined ()
lodash.curry: undefined ()
lru-cache: undefined ()
nanoid: undefined ()
neo-async: undefined ()
next: 10.1.3 => 10.1.3
nope: 1.0.0
ora: undefined ()
postcss-flexbugs-fixes: undefined ()
postcss-loader: undefined ()
postcss-preset-env: undefined ()
postcss-scss: undefined ()
prop-types: ^15.7.2 => 15.7.2
react: 17.0.2 => 17.0.2
react-dom: 17.0.2 => 17.0.2
react-hook-form: ^7.8.6 => 7.17.1
recast: undefined ()
resolve-url-loader: undefined ()
sass-loader: undefined ()
schema-utils: undefined ()
semver: undefined ()
send: undefined ()
source-map: undefined ()
string-hash: undefined ()
strip-ansi: undefined ()
superstruct: 1.0.0
terser: undefined ()
text-table: undefined ()
thread-loader: undefined ()
typanion: 1.0.0
typescript: ^4.3.2 => 4.4.3
unistore: undefined ()
vest: 1.0.0
web-vitals: undefined ()
webpack: undefined ()
webpack-sources: undefined ()
yup: ^0.32.9 => 0.32.9 (1.0.0)
zod: 1.0.0
npmGlobalPackages:
@aws-amplify/cli: 4.48.0
aws-cdk: 1.119.0
create-react-native-app: 1.0.0
ethereumjs-testrpc: 4.1.3
express-generator: 4.15.5
gatsby-cli: 1.1.41
graphcool: 1.4.0
HelloWorld: 0.0.1
n: 7.1.0
npm: 6.14.12
react-native-cli: 0.1.10
react-native: 0.13.2
truffle: 3.4.11
ts-node: 9.0.0
typescript: 4.3.2
vue-cli: 2.9.3
webpack: 1.15.0
Describe the bug
When creating a secondary index using @key directive on a model to generate a new query (not by id) in graphql-api.ts, the resulting query does not return attributes that are custom types and only returns the primitives (or array of primitive) attributes.
Expected behavior
While the get and list methods generated for my data model correctly return the custom types, I would expect the generated queries when querying on a secondary index (via @key) to also return custom types associated within a data model, but they do not.
When running the query in the queries section of the AWS AppSync UI tool (which I got to via the GraphQL API section of the amplify admin UI tool), I am able to get the custom types returned there from my custom query (when specifically asking for them to be returned in the query explorer).
Reproduction steps
- Create data models in the "Datastore" tab of the amplify admin UI tool in AWS.
- Give the data models a custom value (can just be an object that contains other primitives) and make your original model have an array of these custom values.
- In backend/api/[appname]/schema.graphl, add the @key directive to your data model to query by a secondary index (e.g. email instead of id)
- Run amplify codegen (with or without high --max-depth parameters) or amplify pull and amplify push This then updates graphql-api.ts but the generated query is missing the custom types.
- Inside the actual running app, console.log the entire data model object returned by using the custom secondary index query, and see that it is missing the custom values.
Code Snippet
type Obj @model @key(name: "getObjByName", fields: ["name"], queryField: "ObjByName") @auth(rules: [{allow: public}]) {
id: ID!
name: String!
someEnum: EnumName
listOfStrings: [String]
customValues: [CustomValue]
url: AWSURL
actionItems: [ActionItem]
}
The generated code is:
export type ObjByNameQuery = {
companyByName?: {
__typename: "ModelCompanyConnection",
items?: Array< {
__typename: "Company",
id: string,
name: string,
someEnum?: EnumName | null,
listOfStrings?: Array< string | null > | null,
url?: string | null,
_version: number,
_deleted?: boolean | null,
_lastChangedAt: number,
createdAt: string,
updatedAt: string,
} | null > | null,
nextToken?: string | null,
startedAt?: number | null,
} | null,
};
While the getQuery does contain the custom values and is the following:
export type GetObjQuery = {
getObj?: {
__typename: "Obj",
id: string,
name: string,
someEnum?: EnumName | null,
listOfStrings?: Array< string | null > | null,
customValues?: Array< {
__typename: "AnnualValue",
year?: number | null,
amount?: number | null,
unit?: SomeOtherEnum | null,
} | null > | null,
website?: string | null,
actionItems?: Array< {
__typename: "ActionItem",
link?: string | null,
ctaText?: string | null,
text?: string | null,
isActive?: boolean | null,
} | null > | null,
_version: number,
_deleted?: boolean | null,
_lastChangedAt: number,
createdAt: string,
updatedAt: string,
} | null,
};
Log output
// Put your logs below this line
aws-exports.js
/* eslint-disable */
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.
const awsmobile = {
"aws_project_region": "us-east-1",
"aws_appsync_graphqlEndpoint": "https://cssafbuzrnafxc4h2kqnkx53nu.appsync-api.us-east-1.amazonaws.com/graphql",
"aws_appsync_region": "us-east-1",
"aws_appsync_authenticationType": "API_KEY",
"aws_appsync_apiKey": "API KEY"
};
export default awsmobile;
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
@brianykim - I'm looking into this issue, but I do recommend you update the aws-exports info in this ticket to exclude the specific values for security purposes - specifically here, the API key. Thanks!
This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.