2.0.0-beta.29 • Published 3 years ago

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

Weekly downloads
413
License
ISC
Repository
github
Last release
3 years ago

Polaris-logo

polaris-core

NPM version Build Status

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 PolarisServer should 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 PolarisServer with.
  • customContext ((context: any, connection?: Connection) => any - optional) - You can provide the PolarisServer your 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 DataVersionMiddleware and IrrelevantEntitiesMiddleware should be applied to the request.
  • allowSoftDeleteMiddleware (boolean) - Determine if SoftDeleteMiddleware should be applied to the request.
  • allowRealityMiddleware (boolean) - Determine if RealityMiddleware should 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:

2.0.0-beta.66

3 years ago

2.0.0-beta.65

3 years ago

2.0.0-beta.64

3 years ago

2.0.0-beta.63

3 years ago

2.0.0-beta.62

3 years ago

2.0.0-beta.61

3 years ago

2.0.0-beta.60

3 years ago

2.0.0-beta.59

3 years ago

2.0.0-beta.58

3 years ago

2.0.0-beta.57

3 years ago

2.0.0-beta.56

3 years ago

2.0.0-beta.55

3 years ago

2.0.0-beta.54

3 years ago

2.0.0-snapshot.0

3 years ago

2.0.1-snapshot.0

3 years ago

2.0.0-beta.53

3 years ago

2.0.0-beta.52

3 years ago

2.0.0-beta.51

3 years ago

2.0.0-beta.50

3 years ago

2.0.0-beta.49

3 years ago

2.0.0-beta.48

3 years ago

2.0.0-beta.47

3 years ago

2.0.0-beta.46

4 years ago

2.0.0-beta.45

4 years ago

2.0.0-beta.44

4 years ago

2.0.0-beta.43

4 years ago

2.0.0-beta.42

4 years ago

2.0.0-beta.41

4 years ago

2.0.0-beta.40

4 years ago

2.0.0-beta.39

4 years ago

2.0.0-beta.38

4 years ago

2.0.0-beta.37

4 years ago

2.0.0-beta.36

4 years ago

2.0.0-beta.35

4 years ago

2.0.0-beta.34

4 years ago

2.0.0-beta.33

4 years ago

2.0.0-beta.29

4 years ago

2.0.0-beta.27

4 years ago

2.0.0-beta.26

4 years ago

2.0.0-beta.25

4 years ago

2.0.0-beta.24

4 years ago

2.0.0-beta.23

4 years ago

2.0.0-beta.22

4 years ago

2.0.0-beta.21

4 years ago

2.0.0-beta.20

4 years ago

2.0.0-beta.19

4 years ago

2.0.0-beta.18

4 years ago

2.0.0-beta.17

4 years ago

2.0.0-beta.16

4 years ago

2.0.0-beta.15

4 years ago

2.0.0-beta.14

4 years ago

2.0.0-beta.13

4 years ago

2.0.0-beta.12

4 years ago

2.0.0-beta.11

4 years ago

2.0.0-beta.10

4 years ago

2.0.0-beta.9

4 years ago

2.0.0-beta.8

4 years ago

2.0.0-beta.7

4 years ago

2.0.0-beta.6

4 years ago

2.0.0-beta.5

4 years ago

2.0.0-beta.4

4 years ago

2.0.0-beta.3

4 years ago

2.0.0-beta.2

4 years ago

2.0.0-beta.1

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.2.0

4 years ago

1.3.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago