* added array support for pointer permissions
* added tests for array support for pointer permissions
* Postgres fix
* simplify PG, no idea why this works
* Renaming GraphQL Types/Inputs
* Add Native Type to avoid collision
* Use pluralize for renaming
* Fixing tests
* Improve name collision management - tests passsing
* Renaming few more default types
* Rename file input
* Reverting fields types to not collide with the relay spec types
Improver users mutations
* Adding ArrayResult to the reserved list
* Fixing tests
* Add more unit tests to ParseGraphQLSchema
* Test transformClassNameToGraphQL
* Name collision tests
* 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
* 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
* Batch transaction boilerplate
* Refactoring transaction boilerplate
* Independent sessions test
* Transactions - partial
* Missing only one test
* All tests passing for mongo db
* Tests on Travis
* Transactions on postgres
* Fix travis to restart mongodb
* Remove mongodb service and keep only mongodb runner
* MongoDB service back
* Initialize replicaset
* Remove mongodb runner again
* Again only with mongodb-runner and removing cache
* Trying with pretest and posttest
* WiredTiger
* Pretest and posttest again
* Removing inexistent scripts
* wiredTiger
* One more attempt
* Trying another way to run mongodb-runner
* Fixing tests
* Include batch transaction on direct access
* Add tests to direct access
* Add field options to mongo schema metadata
* Add/fix test with fields options
* Add required validation failing test
* Add more tests
* Only set default value if field is undefined
* Fix redis test
* Fix tests
* Test for creating a new class with field options
* Validate default value type
* fix lint (weird)
* Fix lint another way
* Add tests for beforeSave trigger and solve small issue regarding the use of unset in the beforeSave trigger
* 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
* make possible to alter response using the after save trigger like for after find
* code clearing to follow same object checking
* remove console log debug
* fix test unit
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"
}
}
}
}
```
* 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
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.
* Including GraphQL options in CLI - now it was auto-generated
* Improving the way that the headers are passed to the playground
* Including README notes about GraphQL
* Improving final text
* 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