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
This commit is contained in:
committed by
GitHub
parent
922251a398
commit
fe2e95622f
110
src/GraphQL/ParseGraphQLServer.js
Normal file
110
src/GraphQL/ParseGraphQLServer.js
Normal file
@@ -0,0 +1,110 @@
|
||||
import corsMiddleware from 'cors';
|
||||
import bodyParser from 'body-parser';
|
||||
import { graphqlUploadExpress } from 'graphql-upload';
|
||||
import { graphqlExpress } from 'apollo-server-express/dist/expressApollo';
|
||||
import { renderPlaygroundPage } from '@apollographql/graphql-playground-html';
|
||||
import { execute, subscribe } from 'graphql';
|
||||
import { SubscriptionServer } from 'subscriptions-transport-ws';
|
||||
import { handleParseHeaders } from '../middlewares';
|
||||
import requiredParameter from '../requiredParameter';
|
||||
import defaultLogger from '../logger';
|
||||
import { ParseGraphQLSchema } from './ParseGraphQLSchema';
|
||||
|
||||
class ParseGraphQLServer {
|
||||
constructor(parseServer, config) {
|
||||
this.parseServer =
|
||||
parseServer ||
|
||||
requiredParameter('You must provide a parseServer instance!');
|
||||
if (!config || !config.graphQLPath) {
|
||||
requiredParameter('You must provide a config.graphQLPath!');
|
||||
}
|
||||
this.config = config;
|
||||
this.parseGraphQLSchema = new ParseGraphQLSchema(
|
||||
this.parseServer.config.databaseController,
|
||||
(this.parseServer.config && this.parseServer.config.loggerController) ||
|
||||
defaultLogger
|
||||
);
|
||||
}
|
||||
|
||||
async _getGraphQLOptions(req) {
|
||||
return {
|
||||
schema: await this.parseGraphQLSchema.load(),
|
||||
context: {
|
||||
info: req.info,
|
||||
config: req.config,
|
||||
auth: req.auth,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
applyGraphQL(app) {
|
||||
if (!app || !app.use) {
|
||||
requiredParameter('You must provide an Express.js app instance!');
|
||||
}
|
||||
|
||||
const maxUploadSize = this.parseServer.config.maxUploadSize || '20mb';
|
||||
const maxFileSize =
|
||||
(Number(maxUploadSize.slice(0, -2)) * 1024) ^
|
||||
{
|
||||
kb: 1,
|
||||
mb: 2,
|
||||
gb: 3,
|
||||
}[maxUploadSize.slice(-2).toLowerCase()];
|
||||
|
||||
app.use(this.config.graphQLPath, graphqlUploadExpress({ maxFileSize }));
|
||||
app.use(this.config.graphQLPath, corsMiddleware());
|
||||
app.use(this.config.graphQLPath, bodyParser.json());
|
||||
app.use(this.config.graphQLPath, handleParseHeaders);
|
||||
app.use(
|
||||
this.config.graphQLPath,
|
||||
graphqlExpress(async req => await this._getGraphQLOptions(req))
|
||||
);
|
||||
}
|
||||
|
||||
applyPlayground(app) {
|
||||
if (!app || !app.get) {
|
||||
requiredParameter('You must provide an Express.js app instance!');
|
||||
}
|
||||
app.get(
|
||||
this.config.playgroundPath ||
|
||||
requiredParameter(
|
||||
'You must provide a config.playgroundPath to applyPlayground!'
|
||||
),
|
||||
(_req, res) => {
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
res.write(
|
||||
renderPlaygroundPage({
|
||||
endpoint: this.config.graphQLPath,
|
||||
subscriptionEndpoint: this.config.subscriptionsPath,
|
||||
})
|
||||
);
|
||||
res.end();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
createSubscriptions(server) {
|
||||
SubscriptionServer.create(
|
||||
{
|
||||
execute,
|
||||
subscribe,
|
||||
onOperation: async (_message, params, webSocket) =>
|
||||
Object.assign(
|
||||
{},
|
||||
params,
|
||||
await this._getGraphQLOptions(webSocket.upgradeReq)
|
||||
),
|
||||
},
|
||||
{
|
||||
server,
|
||||
path:
|
||||
this.config.subscriptionsPath ||
|
||||
requiredParameter(
|
||||
'You must provide a config.subscriptionsPath to createSubscriptions!'
|
||||
),
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export { ParseGraphQLServer };
|
||||
Reference in New Issue
Block a user