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

GraphQL Object constraints #5715

Merged
merged 12 commits into from
Aug 2, 2019
Merged

GraphQL Object constraints #5715

merged 12 commits into from
Aug 2, 2019

Conversation

douglasmuraoka
Copy link
Contributor

Implements the GraphQL Object constraints, which allows us to filter queries results using the $eq, $lt, $gt, $in, and other Parse supported constraints.
Example:

query {
  objects {
    findMyClass(where: {
      objField: {
        _eq: {
          key: 'foo.bar',
          value: 'hello'
        },
        _gt: {
          key: 'foo.number',
          value: 10
        },
        _lt: {
          key: 'anotherNumber',
          value: 5
        }
      }
    }) {
      results {
        objectId
      }
    }
  }
}

In the example above, we have a Parse class named MyClass, and a field named objField whose type is Object. The object below represents a valid objField and would satisfy all constraints:

{
  "foo": {
    "bar": "hello",
    "number": 11
  },
  "anotherNumber": 4
}

The Object constraint is applied only when using Parse class object type queries. When using "generic" queries such as get and find, this type of constraint is not available.

Implements the GraphQL Object constraints, which allows us to filter queries results using the `$eq`, `$lt`, `$gt`, `$in`, and other Parse supported constraints.
Example:
```
query objects {
  findMyClass(where: {
    objField: {
      _eq: {
        key: 'foo.bar',
        value: 'hello'
      },
      _gt: {
        key: 'foo.number',
        value: 10
      },
      _lt: {
        key: 'anotherNumber',
        value: 5
      }
    }
  }) {
    results {
      objectId
    }
  }
}
```
In the example above, we have the `findMyClass` query (automatically generated for the `MyClass` class), and a field named `objField` whose type is Object. The object below represents a valid `objField` value and would satisfy all constraints:
```
{
  "foo": {
    "bar": "hello",
    "number": 11
  },
  "anotherNumber": 4
}
```
The Object constraint is applied only when using Parse class object type queries. When using "generic" queries such as `get` and `find`, this type of constraint is not available.
@davimacedo
Copy link
Member

It seems not working properly for Postgres. Can you please take a look?

Fixes the $eq, $ne, $gt, and $lt constraints when applied on an Object type field.
@codecov
Copy link

codecov bot commented Jun 24, 2019

Codecov Report

Merging #5715 into master will decrease coverage by 0.01%.
The diff coverage is 92.85%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #5715      +/-   ##
=========================================
- Coverage   93.72%   93.7%   -0.02%     
=========================================
  Files         153     153              
  Lines       10703   10724      +21     
=========================================
+ Hits        10031   10049      +18     
- Misses        672     675       +3
Impacted Files Coverage Δ
src/LiveQuery/ParseLiveQueryServer.js 90.06% <ø> (ø) ⬆️
src/GraphQL/loaders/defaultGraphQLTypes.js 97.43% <100%> (+0.01%) ⬆️
src/GraphQL/loaders/objectsQueries.js 81.37% <100%> (+0.56%) ⬆️
src/Adapters/WebSocketServer/WSSAdapter.js 100% <100%> (ø) ⬆️
src/Options/Definitions.js 100% <100%> (ø) ⬆️
src/Controllers/SchemaController.js 96.37% <100%> (ø) ⬆️
...dapters/Storage/Postgres/PostgresStorageAdapter.js 96.59% <90.32%> (-0.2%) ⬇️
src/RestWrite.js 93.56% <0%> (ø) ⬆️

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 cbcca36...595d7d8. Read the comment docs.

Copy link
Member

@davimacedo davimacedo left a comment

Choose a reason for hiding this comment

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

Send some changes/questions that I think may be required. I also saw some changes in the Postgres adapter. I am little bit afraid of them because I think we don't have good coverage for Postgres with current tests. What do you think? Do you think that the current tests cover the changes you did? Or would it be better to create some additional tests?

src/GraphQL/loaders/defaultGraphQLTypes.js Outdated Show resolved Hide resolved
src/GraphQL/loaders/defaultGraphQLTypes.js Outdated Show resolved Hide resolved
src/GraphQL/loaders/parseClassQueries.js Outdated Show resolved Hide resolved
spec/ParseGraphQLServer.spec.js Outdated Show resolved Hide resolved
src/GraphQL/loaders/defaultGraphQLTypes.js Outdated Show resolved Hide resolved
src/GraphQL/loaders/defaultGraphQLTypes.js Outdated Show resolved Hide resolved
src/GraphQL/loaders/parseClassQueries.js Outdated Show resolved Hide resolved
Copy link
Member

@davimacedo davimacedo left a comment

Choose a reason for hiding this comment

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

LGTM!

@davimacedo davimacedo merged commit ef14ca5 into master Aug 2, 2019
@TomWFox TomWFox deleted the graphql_object_constraint branch August 2, 2019 19:49
UnderratedDev pushed a commit to UnderratedDev/parse-server that referenced this pull request Mar 21, 2020
* GraphQL Object constraints

Implements the GraphQL Object constraints, which allows us to filter queries results using the `$eq`, `$lt`, `$gt`, `$in`, and other Parse supported constraints.
Example:
```
query objects {
  findMyClass(where: {
    objField: {
      _eq: {
        key: 'foo.bar',
        value: 'hello'
      },
      _gt: {
        key: 'foo.number',
        value: 10
      },
      _lt: {
        key: 'anotherNumber',
        value: 5
      }
    }
  }) {
    results {
      objectId
    }
  }
}
```
In the example above, we have the `findMyClass` query (automatically generated for the `MyClass` class), and a field named `objField` whose type is Object. The object below represents a valid `objField` value and would satisfy all constraints:
```
{
  "foo": {
    "bar": "hello",
    "number": 11
  },
  "anotherNumber": 4
}
```
The Object constraint is applied only when using Parse class object type queries. When using "generic" queries such as `get` and `find`, this type of constraint is not available.

* Objects constraints not working on Postgres

Fixes the $eq, $ne, $gt, and $lt constraints when applied on an Object type field.

* Fix object constraint field name

* Fix Postgres constraints indexes

* fix: Object type composed constraints not working

* fix: Rename key and value fields

* refactor: Object constraints for generic queries

* fix: Object constraints not working on Postgres
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.

2 participants