Commit Graph

14 Commits

Author SHA1 Message Date
Antoine Cormouls
4bffdce047 GraphQL: Inline Fragment on Array Fields (#5908)
* Inline Fragment Spec

* Inline Fragment on Arrays

* Fix Test

* Only select the root field

* Requested Changes

* Lazy Loaded ArrayResult
2019-08-14 12:25:28 -07:00
greenkeeper[bot]
4c1be61bed Update mongodb to the latest version 🚀 (#5914)
* fix(package): update mongodb to version 3.3.0

* chore(package): update lockfile package-lock.json

* Fix tests

* Fix GraphQL tests for read preference

* Fix mongo adapter deprecation notice

* Fix the way the connections are checked, return promise when shutting down mongo
2019-08-14 01:25:49 +00:00
Antoine Cormouls
9031961e86 Return specific Type on specific Mutation (#5893)
* Return specific Type on specific Mutation

* Add Optimization on Mutation

* Optimize SignUp
2019-08-12 01:38:59 -07:00
Douglas Muraoka
f81da11b84 fix(GraphQL): Remove "password" output field from _User class (#5889) 2019-08-06 17:21:33 -07:00
Douglas Muraoka
ef14ca530d GraphQL Object constraints (#5715)
* 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
2019-08-02 12:18:07 -07:00
Omair Vaiyani
d3810c2eba GraphQL Configuration Options (#5782)
* add parse-graph-ql configuration for class schema customisation

Not yet tested - essentially an RFC

* refactor and add graphql router, controller and config cache

* fix(GraphQLController): add missing check isEnabled

* chore(GraphQLController): remove awaits from cache put

* chore(GraphQLController): remove check for if its enabled

* refactor(GraphQLController): only use cache if mounted

* chore(GraphQLController): group all validation errors and throw at once

* chore(GraphQLSchema): move transformations into controller validation

* refactor(GraphQL): improve ctrl validation and fix schema usage of config

* refactor(GraphQLSchema): remove code related to additional schema

This code has been moved into a separate feature branch.

* fix(GraphQLSchema): fix incorrect default return type for class configs

* refactor(GraphQLSchema): update staleness check code to account for config

* fix(GraphQLServer): fix regressed tests due to internal schema changes

This will be followed up with a backwards compatability fix for the `ClassFields` issue to avoid breakages for our users

* refactor: rename to ParseGraphQLController for consistency

* fix(ParseGraphQLCtrl): numerous fixes for validity checking

Also includes some minor code refactoring

* chore(GraphQL): minor syntax cleanup

* fix(SchemaController): add _GraphQLConfig to volatile classes

* refactor(ParseGraphQLServer): return update config value in setGraphQLConfig

* testing(ParseGraphQL): add test cases for new graphQLConfig

* fix(GraphQLController): fix issue where config with multiple items was not being mapped to the db

* fix(postgres): add _GraphQLConfig default schema on load

fixes failing postgres tests

* GraphQL @mock directive (#5836)

* Add mock directive
* Include tests for @mock directive

* Fix existing tests due to the change from ClassFields to ClassCreateFields

* fix(parseClassMutations): safer type transformation based on input type

* fix(parseClassMutations): only define necessary input fields

* fix(GraphQL): fix incorrect import paths
2019-07-25 12:46:25 -07:00
Antonio Davi Macedo Coelho de Castro
b605638415 Fix: GraphQL _or operator not working (#5840) 2019-07-23 10:29:38 -03:00
Antonio Davi Macedo Coelho de Castro
2e0940c996 GraphQL @mock directive (#5836)
* Add mock directive
* Include tests for @mock directive
2019-07-22 15:19:40 -03:00
Antonio Davi Macedo Coelho de Castro
71d92aed8d GraphQL Custom Schema (#5821)
This PR empowers the Parse GraphQL API with custom user-defined schema. The developers can now write their own types, queries, and mutations, which will merged with the ones that are automatically generated. The new types are resolved by the application's cloud code functions.

Therefore, regarding https://github.com/parse-community/parse-server/issues/5777, this PR closes the cloud functions needs and also addresses the graphql customization topic. In my view, I think that this PR, together with https://github.com/parse-community/parse-server/pull/5782 and https://github.com/parse-community/parse-server/pull/5818, when merged, closes the issue.

How it works:

1. When initializing ParseGraphQLServer, now the developer can pass a custom schema that will be merged to the auto-generated one:
```
      parseGraphQLServer = new ParseGraphQLServer(parseServer, {
        graphQLPath: '/graphql',
        graphQLCustomTypeDefs: gql`
          extend type Query {
            custom: Custom @namespace
          }
           type Custom {
            hello: String @resolve
            hello2: String @resolve(to: "hello")
            userEcho(user: _UserFields!): _UserClass! @resolve
          }
        `,
      });
```

Note:
- This PR includes a @namespace directive that can be used to the top level field of the nested queries and mutations (it basically just returns an empty object);
- This PR includes a @resolve directive that can be used to notify the Parse GraphQL Server to resolve that field using a cloud code function. The `to` argument specifies the function name. If the `to` argument is not passed, the Parse GraphQL Server will look for a function with the same name of the field;
- This PR allows creating custom types using the auto-generated ones as in `userEcho(user: _UserFields!): _UserClass! @resolve`;
- This PR allows to extend the auto-generated types, as in `extend type Query { ... }`.

2. Once the schema was set, you just need to write regular cloud code functions:
```
      Parse.Cloud.define('hello', async () => {
        return 'Hello world!';
      });

      Parse.Cloud.define('userEcho', async req => {
        return req.params.user;
      });
```

3. Now you are ready to play with your new custom api:
```
query {
  custom {
    hello
    hello2
    userEcho(user: { username: "somefolk" }) {
      username
    }
  }
}
```
should return
```
{
  "data": {
    "custom": {
      "hello": "Hello world!",
      "hello2": "Hello world!",
      "userEcho": {
        "username": "somefolk"
      }
    }
  }
}
```
2019-07-18 16:43:49 -03:00
Antonio Davi Macedo Coelho de Castro
0b86a86209 GraphQL { functions { call } } generic mutation (#5818)
* Generic call function mutation
* Change function return type to any
* First passing test
* Testing errors
* Testing different data types
2019-07-18 16:41:10 -03:00
Douglas Muraoka
f91034ab8c GraphQL: Improve session token error messages (#5753)
* GraphQL: Improve session token error message

Fixes the session token related error messages during GraphQL operations. If any authentication error were thrown, it was not correctly handled by the GraphQL express middleware, and ended responding the request with a JSON parsing error.

* Refactor handleError usage

* Use handleParseErrors middleware to handle invalid session token error

* fix: Status code 400 when session token is invalid

* fix: Undo handleParseErrors middleware change
2019-07-12 13:58:47 -07:00
Douglas Muraoka
2c4031092e GraphQL: /me pointers not working (#5745)
When using the `/me` endpoint to fetch the current user, it does not fetches data from any Pointer data type field, even though the field was defined in the GraphQL schema.
2019-07-02 12:15:46 -07:00
Douglas Muraoka
3d63545ab7 GraphQL: User sign up required fields (#5743) 2019-07-02 12:11:45 -07:00
Antonio Davi Macedo Coelho de Castro
fe2e95622f GraphQL Support (#5674)
* GraphQL boilerplate

* Create GraphQL schema without using gql

* Introducing loaders

* Generic create mutation

* create mutation is now working for any data type

* Create mutation for each parse class - partial

* Adding more data types to the class

* Get parse class query

* Generic get query

* Generic delete mutation

* Parse class delete mutation

* Parse class find mutation

* Generic update mutation

* Parse class update mutation

* Fixing initialization problems

* Installing node-fetch again

* Basic implementation for Pointer

* Constructor tests

* API tests boilerplate

* _getGraphQLOptions

* applyGraphQL tests

* GraphQL API initial tests

* applyPlayground tests

* createSubscriptions tests

* ParseGrapjQLSchema tests file

* ParseGraphQLSchema tests

* TypeValidationError

* TypeValidationError

* parseStringValue test

* parseIntValue tests

* parseBooleanValue tests

* parseDateValue tests

* parseValue tests

* parseListValues tests

* parseObjectFields tests

* Default types tests

* Get tests

* First permission test at generic Get operation

* Fixing prepare data

* ApolloClient does not work well with different queries runnning in paralell with different headers

* ApolloClient does not work well with different queries runnning in paralell with different headers

* User 3 tests

* User 3 tests

* Get level permission tests

* Get User specific tests

* Get now support keys argument

* Get now supports include argument

* Get now supports read preferences

* Adding tests for read preference enum type

* Find basic test

* Find permissions test

* Find where argument test

* Order, skip and limit tests

* Error handler

* Find now supports count

* Test for FindResult type

* Improving find count

* Find max limit test

* Find now supports keys, include and includeAll

* Find now supports read preferences

* Basic Create test

* Generic create mutation tests

* Basic update test

* UpdateResult object type test

* Update level permissions tests

* Error handler for default mutations

* Delete mutation basic test

* Delete mutation level permission tests

* Test for string

* String test

* Date test

* Pointer test

* Relation tests

* Changing objects mutations location

* Changing objects queries location

* Create file mutation

* Test for file fields

* Test for null values

* Changing parse classes operations location

* Objects mutations refactoring

* Class specific create object mutation now working

* Update class specific mutation now working

* Specific class delete mutation now working

* Get class specific mutation now working

* Find class specific query now working without where and sort

* Find query for custom classes working with where partially

* Almost all data types working for specfic class find where

* Now only missing relation, geopoint, file and ACL

* Additional tests with Parse classes queries and mutations

* Now only missing relation, geopoint, file and ACL

* Files

* Fiels are now working

* Excluding missing order test temporarly

* Refactoring dates

* Refactoring files

* Default types review

* Refeactoring object queries

* Refactoring class scalar type

* Refactoring class types

* Geo queries are now working

* Fixing centerSphere

* Allow sort on class specific queries

* Supporting bytes

* ACL constraint

* Temporarly removing xit tests

* Fixing some tests because of schema cache

* Removing session token from users

* Parse.User queries and mutations

* Remove test using fit

* Fixing include test that was failing because of schema cache

* Fixing count test for postgres. Postgres does not count with where={} (legacy problem). We should solve it later

* Fix null values test for postgres. It is evaluating null as undefined (legacy problem) and we should fix is later.

* Fixing schema change test that was failing because of schema cache

* Add GraphQL File type parseLiteral tests

* Refeactoring users

* Including sign up mutation

* Fix failing test

* Improve default GraphQL types tests coverage

* Including some tests for data types

* Including additional pointer test:

* Fixing some tests

* more data type tests

* Include Bytes and Polygon data types tests

* Polygons test

* Merging other tests

* Fixing some postgres tests
2019-06-19 17:19:47 -07:00