0

I had this query runs perfect in AppSync console with no problem:

 query listTftTeamCombos {
      listTftTeamCombos {
        items {
          sortId
          teamId
        }
      }
    }

But when I try to use it in local ide with Vue.js, it gives me validation error:

Validation error of type UnknownType: Unknown type TableTftTeamComboFilterInput

I managed to come up with two query but none of them works:

export const test1 = /* GraphQL */ `
  query ListTftTeamCombos(
    $filter: TableTftTeamComboFilterInput
    $limit: Int
    $nextToken: String
  ) {
    listTftTeamCombos(filter: $filter, limit: $limit, nextToken: $nextToken) {
      items {
        sortId
        teamId
      }
      nextToken
    }
  }
`;

Second query:

export const test2 = /* GraphQL */ `
    query ListTftTeamCombos{
        items: {
          sortId: $sortId
          teamId: $teamId
        }
    }

this is the raw schema from appsync console. (Before generating the schema.graphql which is long and unreadbale.)

input CreateTftTeamComboInput {
    sortId: String!
    teamId: String!
}

input DeleteTftTeamComboInput {
    sortId: String!
    teamId: String!
}

type Mutation {
    createTftTeamCombo(input: CreateTftTeamComboInput!): TftTeamCombo
    updateTftTeamCombo(input: UpdateTftTeamComboInput!): TftTeamCombo
    deleteTftTeamCombo(input: DeleteTftTeamComboInput!): TftTeamCombo
}

type Query {
    getTftTeamCombo(teamId: String!, sortId: String!): TftTeamCombo
    listTftTeamCombos(filter: TableTftTeamComboFilterInput, limit: Int, nextToken: String): TftTeamComboConnection
}

type Subscription {
    onCreateTftTeamCombo(sortId: String, teamId: String): TftTeamCombo
        @aws_subscribe(mutations: ["createTftTeamCombo"])
    onUpdateTftTeamCombo(sortId: String, teamId: String): TftTeamCombo
        @aws_subscribe(mutations: ["updateTftTeamCombo"])
    onDeleteTftTeamCombo(sortId: String, teamId: String): TftTeamCombo
        @aws_subscribe(mutations: ["deleteTftTeamCombo"])
}

input TableBooleanFilterInput {
    ne: Boolean
    eq: Boolean
}

input TableFloatFilterInput {
    ne: Float
    eq: Float
    le: Float
    lt: Float
    ge: Float
    gt: Float
    contains: Float
    notContains: Float
    between: [Float]
}

input TableIDFilterInput {
    ne: ID
    eq: ID
    le: ID
    lt: ID
    ge: ID
    gt: ID
    contains: ID
    notContains: ID
    between: [ID]
    beginsWith: ID
}

input TableIntFilterInput {
    ne: Int
    eq: Int
    le: Int
    lt: Int
    ge: Int
    gt: Int
    contains: Int
    notContains: Int
    between: [Int]
}

input TableStringFilterInput {
    ne: String
    eq: String
    le: String
    lt: String
    ge: String
    gt: String
    contains: String
    notContains: String
    between: [String]
    beginsWith: String
}

input TableTftTeamComboFilterInput {
    sortId: TableStringFilterInput
    teamId: TableStringFilterInput
}

type TftTeamCombo {
    sortId: String!
    teamId: String!
}

type TftTeamComboConnection {
    items: [TftTeamCombo]
    nextToken: String
}

input UpdateTftTeamComboInput {
    sortId: String!
    teamId: String!
}

The file schema.json is auto generated by using the command amplify add codege and i didnt change it.

Should I modify schema.json for my query to work or did i make a mistake when constructing the query?

Thanks in advance.

Sam Min Wong
  • 151
  • 3
  • 18

1 Answers1

0

As per the information you provided, your Vue query and GraphQL schema does not match i.e. TableTftTeamComboFilterInput is not defined in your schema. Your query in AppSync is working because you are not providing any input to it and therefore no validation error. On this note, your second query should work like this:

export const test2 = /* GraphQL */ `
query listTftTeamCombos {
  listTftTeamCombos {
    items {
      sortId
      teamId
    }
  }
}

I think there is problem in how you are making the query.

Myz
  • 818
  • 1
  • 8
  • 21
  • I have tried your query and it gives me syntax error: Syntax Error: Expected Name, found , I have attached the schema auto generated by amplify, many thanks to your help. – Sam Min Wong Jul 05 '20 at 17:46
  • Sorry, I missed the closing parenthesis. Updated the query. – Myz Jul 05 '20 at 18:14
  • It sounds a bit silly but could you please make sure that your schema.json is updated (`npm run-script update-schema`) and verify that TableTftTeamComboFilterInput is in your schema. I tried to test your code using Playground but I did not get any error unless I misspell TableTftTeamComboFilterInput. – Myz Jul 05 '20 at 20:14
  • your latest query gives me 'Validation error of type FieldUndefined: Field 'listTftTeamCombos' in type 'Query' is undefined @ 'listTftTeamCombos'' error, since i can't run (npm run-script update-schema) so I went to appsync console , downloaded and replace the schema.json file in my local path, it still doesnt work. i even rename the query in schema.json and still doesnt work. – Sam Min Wong Jul 05 '20 at 20:48
  • After your help i am getting a hint of how it works, when I define the 'query' it should look for query defined in the schema.json file, then look fot the query name 'listTftTeamCombos' inside in. I did check the query name exists but for some reason it gives me the same error. I deleted the node_modules folder and did npm install, nothing works. – Sam Min Wong Jul 05 '20 at 20:58
  • I have remove the schema.json file in the directory and then run 'npm run dev' without any error in terminal and in chrome console it gives me the same error. lol i really dont know whats going on. – Sam Min Wong Jul 05 '20 at 21:10
  • I was following this doc: 'https://docs.amplify.aws/lib/graphqlapi/getting-started/q/platform/js#create-the-graphql-api' and with no issue, but after that i am trying to get appsync to connect to a existed dynamodb by importing the dynamo db in appsync console and do 'amplify codegen remove' and 'amplify add codegen --apiId xxx' which then gives me the error. then i did all your have asked and still not working, – Sam Min Wong Jul 05 '20 at 21:24