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

feat(amplify_api): GraphQL Query Helper - List #771

Conversation

Equartey
Copy link
Member

@Equartey Equartey commented Aug 2, 2021

Issue #, if available:
Partial implementation of GraphQL model helper feature #308.

Description of changes:
This adds ModelQueries.list(), allows for proper response decoding of PaginatedResults, and relevant unit tests.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Equartey Equartey requested a review from a team as a code owner August 2, 2021 19:02
@codecov-commenter
Copy link

codecov-commenter commented Aug 2, 2021

Codecov Report

Merging #771 (8c12a4d) into feature/graphql_helpers (5c080aa) will increase coverage by 0.07%.
The diff coverage is 73.52%.

@@                     Coverage Diff                     @@
##           feature/graphql_helpers     #771      +/-   ##
===========================================================
+ Coverage                    69.52%   69.59%   +0.07%     
===========================================================
  Files                          269      271       +2     
  Lines                         8921     8950      +29     
  Branches                       361      361              
===========================================================
+ Hits                          6202     6229      +27     
- Misses                        2587     2589       +2     
  Partials                       132      132              
Flag Coverage Δ
android-unit-tests 63.35% <ø> (ø)
flutter-unit-tests 62.01% <73.52%> (+0.42%) ⬆️
ios-unit-tests 75.49% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ify_api/lib/src/graphql/paginated_result_impl.dart 20.00% <20.00%> (ø)
...api/lib/src/graphql/paginated_model_type_impl.dart 91.66% <91.66%> (ø)
packages/amplify_api/lib/model_queries.dart 100.00% <100.00%> (ø)
...y_api/lib/src/graphql/graphql_request_factory.dart 80.70% <100.00%> (+8.77%) ⬆️
...ify_api/lib/src/graphql/model_queries_factory.dart 100.00% <100.00%> (+28.57%) ⬆️

Copy link
Contributor

@dnys1 dnys1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking pretty snazzy! 😄

General comments:

  • Let's make all constructors const and fields final when possible (a good rule of thumb)

I'm also going to recommend changing gears a bit and removing documentArgs from the document build step. Ideally, when building the document, we just look at the schema to see what it accepts for input. We're constructing a generic document, essentially, which can be used for any set of variable values (and this will help with caching later, too). The values for those inputs are passed separately in the GraphQL request, and then the server looks at both to do validation and build the actual query.

Example

A user requests a listTodo operation.

Schema:

type Todo @model {
  id: ID!
  title: String!
  description: String
}

type Query {
  listTodos(filter: ModelTodoFilterInput, limit: Int, nextToken: String): ModelTodoConnection
}

Document we build:

query listTodos($filter: ModelTodoFilterInput, $limit: Int, $nextToken: String) {
  listTodos(filter: $filter, limit: $limit, nextToken: $nextToken) {
    nextToken
    items {
      id
      title
      description
    }
  }
}

Variables (JSON) - nullable variables can be omitted or included as null:

{
  "limit": 100,
  "nextToken": null
}

Copy link
Contributor

@dnys1 dnys1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Booya 😎

Copy link
Contributor

@ragingsquirrel3 ragingsquirrel3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢 it ! Great job.

@Equartey Equartey merged commit 851ba7c into aws-amplify:feature/graphql_helpers Aug 3, 2021
@Equartey Equartey deleted the feat/graphql-helper-list branch August 3, 2021 20:20
@rahul-readwhere
Copy link

Hello ,
I am just curious to know, you mentioned ModelTodoFilterInput in your doc. But I am not able to get this in my schema for any model. Am I missing any update?

@ragingsquirrel3
Copy link
Contributor

@rahul-readwhere were you not able to find the ModelTodoFilterInput in your local schema or in the version you see in the AppSync Console? For a small example I have, I noticed that the ModelTodoFilterInput is in the the schema on AWS AppSync Console under AWS AppSync > [backendName] > Schema. For my case, this was created by Amplify when setting up the API resource in my app, which I created from a very basic schema type Blog @model { id: ID!\n name: String!\n createdAt: AWSDate }. More info about that can be found in https://docs.aws.amazon.com/appsync/latest/devguide/provision-from-schema.html

ragingsquirrel3 pushed a commit that referenced this pull request Oct 5, 2021
* chore(amplify_api): GraphQL helper move dependencies (#729)

* feat(amplify_api): GraphQL helper get query (#742)

* feat(amplify_api): GraphQL Response Decoding (#763)

* feat(amplify_api): GraphQL Query Helper - List  (#771)

* feat(amplify_api): GraphQL Mutate Helper - Create (#778)

* feat(amplify_api): GraphQL Mutate Helper - Update (#779)

* feat(amplify_api): GraphQL Mutate Helper - Delete (#780)

* feat(amplify_api): GraphQL Helpers Integration Tests (#785)

* fix(amplify_api): GraphQL Helper Clean Up (#803)

* some fixes for merge

* fix integration tests and some related analyze issues

* update graphql helpers to pass analysis

* correct some rebase errors

Co-authored-by: Elijah Quartey <[email protected]>
ragingsquirrel3 pushed a commit that referenced this pull request Nov 15, 2021
* chore(amplify_api): GraphQL helper move dependencies (#729)

* feat(amplify_api): GraphQL helper get query (#742)

* feat(amplify_api): GraphQL Response Decoding (#763)

* feat(amplify_api): GraphQL Query Helper - List  (#771)

* feat(amplify_api): GraphQL Mutate Helper - Create (#778)

* feat(amplify_api): GraphQL Mutate Helper - Update (#779)

* feat(amplify_api): GraphQL Mutate Helper - Delete (#780)

* feat(amplify_api): GraphQL Helpers Integration Tests (#785)

* fix(amplify_api): GraphQL Helper Clean Up (#803)

* graphql helpers: slight refactor to datastore interface QueryFieldOpe… (#962)

* Graphql helpers pagination helpers (#947)

* Graphql helpers: query predicates translated to filters and conditions for GraphQL requests (#973)

* chore(amplify_api): graphql helpers, add parent selection set for models with belongsTo, transform JSON in response for parents and children

* chore(amplify_api): parse nested responses recursively

* chore(amplify_api): make data nullable in graphql responses (#1007)

* chore(amplify_api): graphql helpers, mutations on models with parents (#1004)

* feat(amplify_api): Graphql helpers, include parent and decode nested/parent values (#1055)

Co-authored-by: Elijah Quartey <[email protected]>

BREAKING CHANGE: data field nullable in GraphQLResponse
ragingsquirrel3 pushed a commit that referenced this pull request Jan 26, 2022
* feat(amplify_api): model-based graphql helpers (#1076)

* chore(amplify_api): GraphQL helper move dependencies (#729)

* feat(amplify_api): GraphQL helper get query (#742)

* feat(amplify_api): GraphQL Response Decoding (#763)

* feat(amplify_api): GraphQL Query Helper - List  (#771)

* feat(amplify_api): GraphQL Mutate Helper - Create (#778)

* feat(amplify_api): GraphQL Mutate Helper - Update (#779)

* feat(amplify_api): GraphQL Mutate Helper - Delete (#780)

* feat(amplify_api): GraphQL Helpers Integration Tests (#785)

* fix(amplify_api): GraphQL Helper Clean Up (#803)

* graphql helpers: slight refactor to datastore interface QueryFieldOpe… (#962)

* Graphql helpers pagination helpers (#947)

* Graphql helpers: query predicates translated to filters and conditions for GraphQL requests (#973)

* chore(amplify_api): graphql helpers, add parent selection set for models with belongsTo, transform JSON in response for parents and children

* chore(amplify_api): parse nested responses recursively

* chore(amplify_api): make data nullable in graphql responses (#1007)

* chore(amplify_api): graphql helpers, mutations on models with parents (#1004)

* feat(amplify_api): Graphql helpers, include parent and decode nested/parent values (#1055)

Co-authored-by: Elijah Quartey <[email protected]>

BREAKING CHANGE: data field nullable in GraphQLResponse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants