orionjs / orionjs Goto Github PK
View Code? Open in Web Editor NEWA new framework for serverside GraphQL apps
Home Page: https://orionjs.com
License: MIT License
A new framework for serverside GraphQL apps
Home Page: https://orionjs.com
License: MIT License
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.
Please provide a sample example same as orioncms example.
So new developer can easily understand and explore this framework.
Adds to Orionjs a new decorator @UseMiddleware(LogMiddleware)
or @Middleware(LogMiddleware, AuthMiddleware)
to extends and reuse some generic functionalities to resolvers and fields.
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
}
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.
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 chainparams
: are the parameters of the resolverviewer
: are the viewer of the requestinfo
: the resolver information of Apollo (optional)next
is a function to call the next function of middleware chainyou 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:
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.
The most direct alternative is to continue using the current system and to use the middlewares within the resolver implementation.
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.
We need to write examples in the Orionjs documentation and maybe a common patters or style guide.
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
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'
]
}
I'm trying to implement an infinite-scroll query, and only having $page and $limit as params seems limiting for pagination queries.
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)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.