Skip to content

fix(GH-233): Support Inline optional search criteria for singular and plural attributes #251

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

Merged
merged 16 commits into from
Apr 7, 2020

Conversation

igdianov
Copy link
Collaborator

@igdianov igdianov commented Mar 30, 2020

This PR contains the following changes:

query {
  Humans {
    select {
      id
      name
      favoriteDroid(optional:true, where:{name:{LIKE:"R2"}}) {
        name
      }
    }
  }
}

will result in

{
  "data": {
    "Humans": {
      "select": [
        {
          "id": "1000",
          "name": "Luke Skywalker",
          "favoriteDroid": null
        },
        {
          "id": "1001",
          "name": "Darth Vader",
          "favoriteDroid": {
            "name": "R2-D2"
          }
        },
        {
          "id": "1002",
          "name": "Han Solo",
          "favoriteDroid": null
        },
        {
          "id": "1003",
          "name": "Leia Organa",
          "favoriteDroid": null
        },
        {
          "id": "1004",
          "name": "Wilhuff Tarkin",
          "favoriteDroid": null
        }
      ]
    }
  }
}
  • Support for inline filtering of plural attributes, i.e. query
  Authors {
    select {
      id
      name
      books(where: {title: {LIKE: "War"}}) {
        title
      }
    }
  }

will return filtered books for each author

{
  "data": {
    "Authors": {
      "select": [
        {
          "id": 1,
          "name": "Leo Tolstoy",
          "books": [
            {
              "title": "War and Peace"
            }
          ]
        },
        {
          "id": 4,
          "name": "Anton Chekhov",
          "books": []
        },
        {
          "id": 8,
          "name": "Igor Dianov",
          "books": []
        }
      ]
    }
  }
}
  • Support of inline sorting of plural attribute selections i.e. the query
  Authors {
    select {
      id
      name(orderBy: ASC)
      books {
        id
        title(orderBy: DESC)
      }
    }
  }

will sort authors by name in ASC order with books title in DESC order:

{
  "data": {
    "Authors": {
      "select": [
        {
          "id": 4,
          "name": "Anton Chekhov",
          "books": [
            {
              "id": 7,
              "title": "Three Sisters"
            },
            {
              "id": 6,
              "title": "The Seagull"
            },
            {
              "id": 5,
              "title": "The Cherry Orchard"
            }
          ]
        },
        {
          "id": 8,
          "name": "Igor Dianov",
          "books": []
        },
        {
          "id": 1,
          "name": "Leo Tolstoy",
          "books": [
            {
              "id": 2,
              "title": "War and Peace"
            },
            {
              "id": 3,
              "title": "Anna Karenina"
            }
          ]
        }
      ]
    }
  }
}
  • Support for aliases, i.e.
{
  Authors {
    select {
      id
      name
      War: books(where: {title: {LIKE: "War"}}) {
        title
      }
      Anna: books(where: {title: {LIKE: "Anna"}}) {
        title
      }
    }
  }
}

will return the following result:

{
  "data": {
    "Authors": {
      "select": [
        {
          "id": 1,
          "name": "Leo Tolstoy",
          "War": [
            {
              "title": "War and Peace"
            }
          ],
          "Anna": [
            {
              "title": "Anna Karenina"
            }
          ]
        },
        {
          "id": 4,
          "name": "Anton Chekhov",
          "War": [],
          "Anna": []
        },
        {
          "id": 8,
          "name": "Igor Dianov",
          "War": [],
          "Anna": []
        }
      ]
    }
  }
}

In order to support inline search criteria with optional association, the framework is now using GraphQL Java Dataloader in order to optimize query perfromance.

@igdianov igdianov self-assigned this Mar 30, 2020
@codecov
Copy link

codecov bot commented Mar 30, 2020

Codecov Report

Merging #251 into master will increase coverage by 1.47%.
The diff coverage is 89.20%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #251      +/-   ##
============================================
+ Coverage     70.86%   72.33%   +1.47%     
- Complexity      957     1025      +68     
============================================
  Files            66       71       +5     
  Lines          4434     4674     +240     
  Branches        661      674      +13     
============================================
+ Hits           3142     3381     +239     
+ Misses         1013     1005       -8     
- Partials        279      288       +9     
Impacted Files Coverage Δ Complexity Δ
.../query/schema/impl/GraphQLJpaToOneDataFetcher.java 70.37% <70.37%> (ø) 5.00 <5.00> (?)
...ures/graphql/jpa/query/support/GraphQLSupport.java 80.59% <70.58%> (+4.59%) 28.00 <6.00> (+8.00)
.../schema/impl/GraphQLJpaExecutorContextFactory.java 76.31% <76.92%> (+0.31%) 12.00 <4.00> (+4.00)
.../jpa/query/schema/impl/GraphQLJpaQueryFactory.java 78.40% <86.40%> (+2.66%) 219.00 <29.00> (+24.00)
...a/query/schema/impl/GraphQLJpaExecutorContext.java 97.82% <95.45%> (-2.18%) 10.00 <5.00> (+3.00) ⬇️
...hql/jpa/query/schema/impl/BatchLoaderRegistry.java 100.00% <100.00%> (ø) 8.00 <8.00> (?)
...jpa/query/schema/impl/GraphQLJpaSchemaBuilder.java 89.09% <100.00%> (+0.47%) 127.00 <1.00> (+1.00)
...query/schema/impl/GraphQLJpaToManyDataFetcher.java 100.00% <100.00%> (ø) 6.00 <6.00> (?)
...schema/impl/GraphQLJpaToManyMappedBatchLoader.java 100.00% <100.00%> (ø) 3.00 <3.00> (?)
.../schema/impl/GraphQLJpaToOneMappedBatchLoader.java 100.00% <100.00%> (ø) 3.00 <3.00> (?)
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4697268...a2741f3. Read the comment docs.

@igdianov igdianov changed the title fix: add ON condition on the right side of collection join fetch criteria fix(GH-233): Inline optional with where is not optional Apr 6, 2020
@igdianov igdianov changed the title fix(GH-233): Inline optional with where is not optional fix(GH-233): Support Inline optional search criteria for singular and plural attributes Apr 7, 2020
@igdianov igdianov merged commit bb44a34 into master Apr 7, 2020
@igdianov igdianov deleted the fix-fetch-join-with-condition branch April 8, 2020 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inline optional with where is not optional
1 participant