@enigmatis/polaris-core v2.0.0-beta.29

polaris-core
Polaris is a set of libraries that help you create the perfect graphql service, integrated with type orm and the hottest API standards. polaris-core organizes all of the libraries for you, and let you create your graphql service as easily as it can be.
Features
- GraphQL service creation (integrated with apollo-server & express)
- Auto soft deletion of entities
- Fetching Deltas of entities (including irrelevant entities)
- Support realities
- Standard errors
- Standard logs
- Standard GraphQL scalars
PolarisServer
This is the server that you will use in order to create your own standardized GraphQL server.\
PolarisServer uses ApolloServer and starts the server with Express.
PolarisServerConfig
Through this interface you should set the following configurations which will be supplied to the PolarisServer:
- typeDefs (any) - The GraphQL schema written in SDL (Schema Definition Language). This will be used in order to create your GraphQL API.
- resolvers (any) - The GraphQL resolvers that will be tied to your GraphQL schema. This object contains functions and logic for the GraphQL engine to invoke when using fields from the schema.
- port (number) - Specify a port the
PolarisServershould start the server on. - applicationProperties (ApplicationProperties - optional) - Properties that describe your repository. If you don't provide those properties, the core will put 'v1' in the version.
- customMiddlewares (any[] - optional) - Custom middlewares that can be provided the
PolarisServerwith. - customContext ((context: any, connection?: Connection) => any - optional) - You can provide the
PolarisServeryour own custom context. If you do not set your custom context, the core will use a default context. - loggerConfiguration (LoggerConfiguration - optional) - This is an interface that defines the logger in the
PolarisServer. If you do not provide this property, the core will use default values for the logger. - middlewareConfiguration (MiddlewareConfiguration - optional) - This is an interface that defines what core middlewares should be activated/disabled.
- connection (Connection - optional) - This class represents your connection with the database. Used in the core middlewares.
MiddlewareConfiguration
As mentioned above, this interface defines what core middlewares should be activated/disabled.
- allowDataVersionAndIrrelevantEntitiesMiddleware (boolean) - Determine if
DataVersionMiddlewareandIrrelevantEntitiesMiddlewareshould be applied to the request. - allowSoftDeleteMiddleware (boolean) - Determine if
SoftDeleteMiddlewareshould be applied to the request. - allowRealityMiddleware (boolean) - Determine if
RealityMiddlewareshould be applied to the request.
Custom context
First we will define the new context type, pay attention that we just added a new field in the root of the context, and a new header in the request headers object.
import { PolarisGraphQLContext, PolarisRequestHeaders } from '@enigmatis/polaris-core';
interface CustomRequestHeaders extends PolarisRequestHeaders {
customHeader?: string | string[];
}
export interface CustomContext extends PolarisGraphQLContext {
customField: number;
requestHeaders: CustomRequestHeaders;
}Then we will pass the custom context like this:
import { ExpressContext, PolarisServer } from '@enigmatis/polaris-core';
const typeDefs = `...`;
const resolvers = { ... };
const customContext = (context: ExpressContext): Partial<CustomContext> => {
const { req } = context;
return {
customField: 1000,
requestHeaders: {
customHeader: req.headers['custom-header'],
},
};
};
const server = new PolarisServer({
typeDefs,
resolvers,
port: 8082,
customContext,
});Example
import { ApplicationProperties, PolarisServer } from '@enigmatis/polaris-core';
const typeDefs = `
type Query {
allPersons: [Person]
}
type Person implements RepositoryEntity {
id: String!
deleted: Boolean!
createdBy: String!
creationTime: DateTime!
lastUpdatedBy: String
lastUpdateTime: DateTime
realityId: Int!
name: String
}
`;
const resolvers = {
Query: {
allPersons: () => [
{ name: 'foo bar', realityId: 0, deleted: false, dataVersion: 2 },
{ name: 'superman', realityId: 0, deleted: true, dataVersion: 3 },
{ name: 'hello world', realityId: 1, deleted: true, dataVersion: 3 },
{ name: 'something', realityId: 1, deleted: false, dataVersion: 4 },
],
},
};
const applicationProperties: ApplicationProperties = {
id: 'p0laris-c0re',
name: 'polaris-core',
version: 'v1',
environment: 'environment',
component: 'component',
};
const server = new PolarisServer({
typeDefs,
resolvers,
port: 4000,
applicationProperties,
});
server.start();For any additional help and requests, feel free to contact us :smile:
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago