0

I am trying to query by passing in the name field but I get two different errors.

"Validation error of type MissingFieldArgument: 
  Missing field argument id @ 'getBlog'"
"Validation error of type UnknownArgument: 
  Unknown field argument name @ 'getBlog'"

I was able to successfully query it with the id field. Im new to graphql and im using this on my app that also uses aws amplify and aws appsync.

schema.graphql

type Blog @model {
  id: ID!
  name: String!
  posts: [Post] @connection(keyName: "byBlog", fields: ["id"])
}

queries.ts

// this is an auto generated file. This will be overwritten

export const getBlog = /* GraphQL */ `
  query GetBlog($name: String!) { //changed from ($id: ID!)
    getBlog(name: $name) { //changed from (id: $id)
      id
      name
      posts {
        items {
          id
          title
          blogID
          createdAt
          updatedAt
        }
        nextToken
      }
      createdAt
      updatedAt
    }
  }
`;

app.tsx

const getRecord = async () => {
        const result = await API.graphql(graphqlOperation(getBlog, {name: "testing"}))
        console.log(result) 
    }

I also tried pushing it to aws amplify push but it detected no changes. I didnt expect it to as i didnt change anything in the schema, only the queries. thanks in advance

1 Answer 1

1

If you look at your GraphQL schema you should see the definition for the GetBlog query. It likely looks like:

query {
  GetBlog(id: ID!): Blog
}

That particular query can only be queried by id. Assuming you have control of the server you should also be able to define a GetBlogByName query:

query {
  GetBlogByName(name: String): Blog
}

But then it will be up to you to ensure that name is unique or deal with potentially >1 response.

Sign up to request clarification or add additional context in comments.

2 Comments

my result i get back is "data": Object {"GetBlogByName": null,}
Good news - you made it past type checking. Now you'll need to create the GetBlogByName resolver function as well on the server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.