How to do filteration in AWS Amplify GraphQL Client
I'm trying to implement GraphQL filter using Amplify GraphQL Client. I got a list of todos and wanted to retrieve list of todos that has status complete.
The Documentation only show how to get all items and single item
const allTodos = await API.graphql(graphqlOperation(queries.listTodos));
console.log(allTodos);
Could someone please point me how to apply filter to the listTodos so that it return todos with status complete only.
I tried to do the following but it is wrong.
API.graphql(graphqlOperation(queries.listTodos(filter: {
status: {
eq: "completed"
}
})));
reactjs react-native graphql aws-appsync aws-amplify
add a comment |
I'm trying to implement GraphQL filter using Amplify GraphQL Client. I got a list of todos and wanted to retrieve list of todos that has status complete.
The Documentation only show how to get all items and single item
const allTodos = await API.graphql(graphqlOperation(queries.listTodos));
console.log(allTodos);
Could someone please point me how to apply filter to the listTodos so that it return todos with status complete only.
I tried to do the following but it is wrong.
API.graphql(graphqlOperation(queries.listTodos(filter: {
status: {
eq: "completed"
}
})));
reactjs react-native graphql aws-appsync aws-amplify
What does your schema and request mapping template look like? Does listTodos query take in a filter input or something? I know that AppSync generates these filter inputs for you if you choose to start with a sample schema
– Lisa M Shon
Dec 28 '18 at 1:27
yes, the code was auto generate by the amplify codegen. so it take filter, limit and next token
– Mohammad Harith
Dec 29 '18 at 2:06
add a comment |
I'm trying to implement GraphQL filter using Amplify GraphQL Client. I got a list of todos and wanted to retrieve list of todos that has status complete.
The Documentation only show how to get all items and single item
const allTodos = await API.graphql(graphqlOperation(queries.listTodos));
console.log(allTodos);
Could someone please point me how to apply filter to the listTodos so that it return todos with status complete only.
I tried to do the following but it is wrong.
API.graphql(graphqlOperation(queries.listTodos(filter: {
status: {
eq: "completed"
}
})));
reactjs react-native graphql aws-appsync aws-amplify
I'm trying to implement GraphQL filter using Amplify GraphQL Client. I got a list of todos and wanted to retrieve list of todos that has status complete.
The Documentation only show how to get all items and single item
const allTodos = await API.graphql(graphqlOperation(queries.listTodos));
console.log(allTodos);
Could someone please point me how to apply filter to the listTodos so that it return todos with status complete only.
I tried to do the following but it is wrong.
API.graphql(graphqlOperation(queries.listTodos(filter: {
status: {
eq: "completed"
}
})));
reactjs react-native graphql aws-appsync aws-amplify
reactjs react-native graphql aws-appsync aws-amplify
asked Dec 27 '18 at 15:43
Mohammad Harith
113
113
What does your schema and request mapping template look like? Does listTodos query take in a filter input or something? I know that AppSync generates these filter inputs for you if you choose to start with a sample schema
– Lisa M Shon
Dec 28 '18 at 1:27
yes, the code was auto generate by the amplify codegen. so it take filter, limit and next token
– Mohammad Harith
Dec 29 '18 at 2:06
add a comment |
What does your schema and request mapping template look like? Does listTodos query take in a filter input or something? I know that AppSync generates these filter inputs for you if you choose to start with a sample schema
– Lisa M Shon
Dec 28 '18 at 1:27
yes, the code was auto generate by the amplify codegen. so it take filter, limit and next token
– Mohammad Harith
Dec 29 '18 at 2:06
What does your schema and request mapping template look like? Does listTodos query take in a filter input or something? I know that AppSync generates these filter inputs for you if you choose to start with a sample schema
– Lisa M Shon
Dec 28 '18 at 1:27
What does your schema and request mapping template look like? Does listTodos query take in a filter input or something? I know that AppSync generates these filter inputs for you if you choose to start with a sample schema
– Lisa M Shon
Dec 28 '18 at 1:27
yes, the code was auto generate by the amplify codegen. so it take filter, limit and next token
– Mohammad Harith
Dec 29 '18 at 2:06
yes, the code was auto generate by the amplify codegen. so it take filter, limit and next token
– Mohammad Harith
Dec 29 '18 at 2:06
add a comment |
1 Answer
1
active
oldest
votes
I think I have an answer to your question, but I also have a similar question regarding the AWS Amplify codegen
queries, mutations, etc. If you look at the code that was generated inside of ~/graphql
folder, you'll find a declaration file similar to this:
export const listOrganizations = `query ListOrganizations(
$filter: ModelOrganizationFilterInput
$limit: Int
$nextToken: String
) {
listOrganizations(filter: $filter, limit: $limit, nextToken: $nextToken) {
items {
id
name
address
}
nextToken
}
}
`;
You can see here that the first parameter to the ListOrganizations
query (in your case, ListTodos
query) takes a first argument of filter: $filter
. I have figured out so far that you can modify this query by doing the following...
API.graphql(graphqlOperation(queries.listTodos, {
filter: {
status: {
eq: "completed"
}
}
})));
This should filter out all Todos except the ones where their status
is equal to completed
. The problem that I am having is that I want to enable different levels of access control such that anyone with a Cognito User Pool Group of Admin
may view @model
as well as the @owner
. And I was able to get this all working using the @auth
transformer, but now my problem is that on some screens, I only want to display certain entities that are the owner
of that entity and because I am also an Admin
, the API defaults to getting me everything. I want to use this @filter
or ModelOrganizationFilterInput
to only give me the data where I am the owner. The only way I have found to do this was to add the owner
field to my Schema, but then the API always provides the owner field and I want to filter that field out.
The only documentation that I can find on how the aws-amplify
API
and graphqlOperation
methods is here: https://aws-amplify.github.io/docs/js/api but there are not many examples and they don't show much of how the API works on the client. I'm stuck.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53947508%2fhow-to-do-filteration-in-aws-amplify-graphql-client%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think I have an answer to your question, but I also have a similar question regarding the AWS Amplify codegen
queries, mutations, etc. If you look at the code that was generated inside of ~/graphql
folder, you'll find a declaration file similar to this:
export const listOrganizations = `query ListOrganizations(
$filter: ModelOrganizationFilterInput
$limit: Int
$nextToken: String
) {
listOrganizations(filter: $filter, limit: $limit, nextToken: $nextToken) {
items {
id
name
address
}
nextToken
}
}
`;
You can see here that the first parameter to the ListOrganizations
query (in your case, ListTodos
query) takes a first argument of filter: $filter
. I have figured out so far that you can modify this query by doing the following...
API.graphql(graphqlOperation(queries.listTodos, {
filter: {
status: {
eq: "completed"
}
}
})));
This should filter out all Todos except the ones where their status
is equal to completed
. The problem that I am having is that I want to enable different levels of access control such that anyone with a Cognito User Pool Group of Admin
may view @model
as well as the @owner
. And I was able to get this all working using the @auth
transformer, but now my problem is that on some screens, I only want to display certain entities that are the owner
of that entity and because I am also an Admin
, the API defaults to getting me everything. I want to use this @filter
or ModelOrganizationFilterInput
to only give me the data where I am the owner. The only way I have found to do this was to add the owner
field to my Schema, but then the API always provides the owner field and I want to filter that field out.
The only documentation that I can find on how the aws-amplify
API
and graphqlOperation
methods is here: https://aws-amplify.github.io/docs/js/api but there are not many examples and they don't show much of how the API works on the client. I'm stuck.
add a comment |
I think I have an answer to your question, but I also have a similar question regarding the AWS Amplify codegen
queries, mutations, etc. If you look at the code that was generated inside of ~/graphql
folder, you'll find a declaration file similar to this:
export const listOrganizations = `query ListOrganizations(
$filter: ModelOrganizationFilterInput
$limit: Int
$nextToken: String
) {
listOrganizations(filter: $filter, limit: $limit, nextToken: $nextToken) {
items {
id
name
address
}
nextToken
}
}
`;
You can see here that the first parameter to the ListOrganizations
query (in your case, ListTodos
query) takes a first argument of filter: $filter
. I have figured out so far that you can modify this query by doing the following...
API.graphql(graphqlOperation(queries.listTodos, {
filter: {
status: {
eq: "completed"
}
}
})));
This should filter out all Todos except the ones where their status
is equal to completed
. The problem that I am having is that I want to enable different levels of access control such that anyone with a Cognito User Pool Group of Admin
may view @model
as well as the @owner
. And I was able to get this all working using the @auth
transformer, but now my problem is that on some screens, I only want to display certain entities that are the owner
of that entity and because I am also an Admin
, the API defaults to getting me everything. I want to use this @filter
or ModelOrganizationFilterInput
to only give me the data where I am the owner. The only way I have found to do this was to add the owner
field to my Schema, but then the API always provides the owner field and I want to filter that field out.
The only documentation that I can find on how the aws-amplify
API
and graphqlOperation
methods is here: https://aws-amplify.github.io/docs/js/api but there are not many examples and they don't show much of how the API works on the client. I'm stuck.
add a comment |
I think I have an answer to your question, but I also have a similar question regarding the AWS Amplify codegen
queries, mutations, etc. If you look at the code that was generated inside of ~/graphql
folder, you'll find a declaration file similar to this:
export const listOrganizations = `query ListOrganizations(
$filter: ModelOrganizationFilterInput
$limit: Int
$nextToken: String
) {
listOrganizations(filter: $filter, limit: $limit, nextToken: $nextToken) {
items {
id
name
address
}
nextToken
}
}
`;
You can see here that the first parameter to the ListOrganizations
query (in your case, ListTodos
query) takes a first argument of filter: $filter
. I have figured out so far that you can modify this query by doing the following...
API.graphql(graphqlOperation(queries.listTodos, {
filter: {
status: {
eq: "completed"
}
}
})));
This should filter out all Todos except the ones where their status
is equal to completed
. The problem that I am having is that I want to enable different levels of access control such that anyone with a Cognito User Pool Group of Admin
may view @model
as well as the @owner
. And I was able to get this all working using the @auth
transformer, but now my problem is that on some screens, I only want to display certain entities that are the owner
of that entity and because I am also an Admin
, the API defaults to getting me everything. I want to use this @filter
or ModelOrganizationFilterInput
to only give me the data where I am the owner. The only way I have found to do this was to add the owner
field to my Schema, but then the API always provides the owner field and I want to filter that field out.
The only documentation that I can find on how the aws-amplify
API
and graphqlOperation
methods is here: https://aws-amplify.github.io/docs/js/api but there are not many examples and they don't show much of how the API works on the client. I'm stuck.
I think I have an answer to your question, but I also have a similar question regarding the AWS Amplify codegen
queries, mutations, etc. If you look at the code that was generated inside of ~/graphql
folder, you'll find a declaration file similar to this:
export const listOrganizations = `query ListOrganizations(
$filter: ModelOrganizationFilterInput
$limit: Int
$nextToken: String
) {
listOrganizations(filter: $filter, limit: $limit, nextToken: $nextToken) {
items {
id
name
address
}
nextToken
}
}
`;
You can see here that the first parameter to the ListOrganizations
query (in your case, ListTodos
query) takes a first argument of filter: $filter
. I have figured out so far that you can modify this query by doing the following...
API.graphql(graphqlOperation(queries.listTodos, {
filter: {
status: {
eq: "completed"
}
}
})));
This should filter out all Todos except the ones where their status
is equal to completed
. The problem that I am having is that I want to enable different levels of access control such that anyone with a Cognito User Pool Group of Admin
may view @model
as well as the @owner
. And I was able to get this all working using the @auth
transformer, but now my problem is that on some screens, I only want to display certain entities that are the owner
of that entity and because I am also an Admin
, the API defaults to getting me everything. I want to use this @filter
or ModelOrganizationFilterInput
to only give me the data where I am the owner. The only way I have found to do this was to add the owner
field to my Schema, but then the API always provides the owner field and I want to filter that field out.
The only documentation that I can find on how the aws-amplify
API
and graphqlOperation
methods is here: https://aws-amplify.github.io/docs/js/api but there are not many examples and they don't show much of how the API works on the client. I'm stuck.
answered yesterday
SuperVeetz
1,16021226
1,16021226
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53947508%2fhow-to-do-filteration-in-aws-amplify-graphql-client%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What does your schema and request mapping template look like? Does listTodos query take in a filter input or something? I know that AppSync generates these filter inputs for you if you choose to start with a sample schema
– Lisa M Shon
Dec 28 '18 at 1:27
yes, the code was auto generate by the amplify codegen. so it take filter, limit and next token
– Mohammad Harith
Dec 29 '18 at 2:06