Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated custom query for @key directive, doesn't return custom non-model types within data model #553

Closed
3 tasks done
brianykim opened this issue Oct 13, 2021 · 2 comments
Assignees
Labels
bug Something isn't working p2 transferred Issue has been transferred from another Amplify repository

Comments

@brianykim
Copy link

brianykim commented Oct 13, 2021

Before opening, please confirm:

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

  1. Create data models in the "Datastore" tab of the amplify admin UI tool in AWS.
  2. 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.
  3. 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)
  4. 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.
  5. 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

@chrisbonifacio chrisbonifacio self-assigned this Oct 13, 2021
@chrisbonifacio chrisbonifacio added the pending-triage Issues that need further discussion to determine label Oct 13, 2021
@david-mcafee
Copy link
Contributor

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

@chrisbonifacio chrisbonifacio added pending-response and removed pending-triage Issues that need further discussion to determine pending-response labels Oct 29, 2021
@manueliglesias manueliglesias transferred this issue from aws-amplify/amplify-js Mar 6, 2023
@manueliglesias manueliglesias added the transferred Issue has been transferred from another Amplify repository label Mar 6, 2023
@alharris-at alharris-at transferred this issue from aws-amplify/amplify-category-api Mar 6, 2023
@alharris-at alharris-at added bug Something isn't working p2 labels Mar 6, 2023
@dpilch dpilch closed this as completed Jul 1, 2024
Copy link

github-actions bot commented Jul 1, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p2 transferred Issue has been transferred from another Amplify repository
Projects
None yet
Development

No branches or pull requests

6 participants