Git Product home page Git Product logo

orionjs's Introduction

Orionjs

A Node framework to build GraphQL server apps.

orionjs.com

Development

In order to deploy orionjs in your local you have to do the following:

  1. Fork the repo
  2. Clone the project forked
  3. Inside the folder created with the clone command, run the following command:
yarn install
  1. Then run the following command to bootstrap the project
yarn bootstrap
  1. Then we need to link an specific package you need with the following command (for example job package):
cd packages/jobs
yarn link
  1. In your project that is using orionjs, you need to run the following command in order to use the local instance of the package:
yarn link "@orion-js/jobs"

orionjs's People

Contributors

bermann avatar daruz14 avatar dependabot[bot] avatar diegoolavarria avatar dmerrill6 avatar ireerodriguez avatar jaletelier avatar jjgumucio avatar mleve avatar morph3o avatar nicolaslopezj avatar raicp avatar sebaiturravaldes avatar uner4s avatar vasquezlricardo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

orionjs's Issues

Problem after upgrading @orion-js/graphql-client to v1.0.6

After upgrading /graphql-client, Apollo doesn't seem to manage the store session correctly. When logging out, I get the following error:

"Unhandled error Network error: Store reset while query was in flight (not completed in link chain) Error: Network error: Store reset while query was in flight (not completed in link chain)"

It seems that the problem comes from this commit: be7522e

Add a way to configure body size limits.

Our app has an import and export function, handled by GraphQL.

However, when uploading large amounts of data (> 1MB), it breaks, because of the default limit of 1 MB for the request body.

Ideally, this should be configurable, either by an environment variable or some other mechanism.

Error with @orion-js/jobs v.1.5.0

I got the following error when upgrading @orion-js/jobs from v.1.4.2 to v.1.5.0

Sentry Logger [Warn]: No DSN provided, backend will not do anything.
TypeError: (0 , _app.config) is not a function
at _default (/home/diego/Projects/recylink/server/node_modules/@orion-js/jobs/lib/job/getExecute.js:25:33)
at _default (/home/diego/Projects/recylink/server/node_modules/@orion-js/jobs/lib/job/index.js:47:44)
at Object. (/home/xxx/xxx/xxx/server/app/jobs/checkUserRegistration/index.js:4:16)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object. (/home/xxx/xxx/xxx/server/app/resolvers/Auth/sendEmailVerificationToken.js:3:1)
Exit code: 1

as you can see, it shows an absolute route when calling a job (I edited the route for privacy)

Not execute the app

When I run orion start after creating a new project get the fallowing error.

Error: spawn mongod ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
    at onErrorNT (internal/child_process.js:464:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn mongod',
  path: 'mongod',
  spawnargs: [
    '--dbpath=.orion/db/data',
    '--port=3001',
    '--logpath',
    '.orion/db/logs/mongolog.log'
  ]
}

RFC: Async middlewares to resolvers and fields

  • Start Date: 2023-01-17
  • RFC PR: (to do)

Summary

Adds to Orionjs a new decorator @UseMiddleware(LogMiddleware) or @Middleware(LogMiddleware, AuthMiddleware) to extends and reuse some generic functionalities to resolvers and fields.

Basic example

Without middlewares we need to call all generic functions inside the resolver implementation

@Mutation({
  params: {resourceId: {type: String}, updates: {type: UpdateResouceModel}},
  returns: Resouce
})
async updateResouce(params: {resourceId: ResourceId; updates: UpdateType}, viewer: Viewer) {
  const resource = await this.resourcesRepo.getResourceById(params.resourceId)
  if (!resource) return
  await checkWebsitePermission(resource.websiteId, viewer)
  await logger({action: 'update', resolver: 'updateResource', viewer, resource})
  const updatedResource = await this.tabsRepo.updateTab(params.tabId, params.updates)
  ... do some other logic ...
  return updatedResource
}

With middlewares decorator we can attach generic functions to the resolver function

const checkWebsitePermissionMw = ({resouce, viewer}, next) => await checkWebsitePermission(resource.websiteId, viewer)
const loggerMw = ({resouce, viewer}, next) =>  await logger({action: 'update', resolver: 'updateResource', viewer, resource})

@Mutation({
   params: {resourceId: {type: String}, updates: {type: UpdateResouceModel}},
   returns: Resouce
 })
@Middleware(checkWebsitePermissionMw, loggerMw)
async updateResouce(params: {resourceId: ResourceId; updates: UpdateType}, viewer: Viewer) {
  const resource = await this.resourcesRepo.getResourceById(params.resourceId)
  if (!resource) return
  const updatedResource = await this.tabsRepo.updateTab(params.tabId, params.updates)
  ... do some other logic ...
  return updatedResource
}

You can also adds middlewares to fields definitions on schema

const timerMw = async ({resource}, next) => {
  console.time('timer')
  const response = await next()
  console.timeEnd('timer')
  return response
}

const loggerMw = ({resource}, next) => {
  console.log('access to code field')
  return next()
}

const permissionMw = ({viewer}, next) => {
  if(!viewer.checkRoles('admin')) return null
  return next()
}

@TypedSchema()
export class Resouce {
  @Prop()
  _id: ResouceId

  @Prop()
  @Middleware(timerMw, loggerMw, permissionMw)
  code: string

  @Prop({optional: true})
  description?: string
}

Motivation

The main motivation of using middlewares is to be able to have reusable pieces of code and use them in resolvers when required. In this way, we can extend the capabilities of a resolver or field and give power to Orionjs to be used in different contexts.

Detailed design

Middleware are pieces of reusable code that can be easily attached to resolvers and fields. By using middleware we can extract the commonly used code from our resolvers and then declaratively attach it using a decorator or even registering it globally.

The proposed API interface is:

({parent, params, viewer, info}, next) => {}

Where:

  • parent: its the parent field of the resolver chain
  • params: are the parameters of the resolver
  • viewer: are the viewer of the request
  • info: the resolver information of Apollo (optional)
  • next is a function to call the next function of middleware chain

you can add a middleware with the @Middleware() decorator.

@Middlewares(loggerMw) // with one middleware
@Middlewares(checkWebsitePermissionMw, loggerMw) // with more than one

With async middlewares you can do before and after actions:

const middleware = ({ parent, params, viewer, info }, next) => {
  /* code before */
  const result = await next()
  /* code after */
  return result
}

The inspiration comes from:

Drawbacks

One of the main disadvantages is that the new middleware decorator affects the general understanding of orionjs, it is necessary to define well the interface that the middlewares will have to make it easy to use.

In addition, the use of middleware in the fields makes it necessary to create an additional resolver (internal to orionjs) to be able to execute the resolvers before returning the value of the field.

The implementation can be complex but you have to rely on Koajs middleware, specifically compose repo.

Alternatives

The most direct alternative is to continue using the current system and to use the middlewares within the resolver implementation.

Adoption strategy

The adoption strategy is incremental, since this is not a breaking change. It can be used as needed and update old implementations to use middlewares.

How we teach this

We need to write examples in the Orionjs documentation and maybe a common patters or style guide.

Unresolved questions

  • Define decorator name (or accept the proposed)
  • Define middleware interface arguments (or accept the proposed)
  • Define how use the middlewares with fields

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.