feat(GraphQL): Initial revision of APIv2 GraphQL
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
const { DateResolver, DateTimeResolver } = require('graphql-scalars');
|
||||
const { Account, User, Company } = require('../../Domain');
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Queries
|
||||
//////////////////////////////////////////////
|
||||
async function account( args, context ) {
|
||||
const account = new Account( context.graphQLContext.userId );
|
||||
return account;
|
||||
}
|
||||
|
||||
async function profile( args, context ) {
|
||||
const profile = new User( context.graphQLContext.userId );
|
||||
return profile;
|
||||
}
|
||||
|
||||
async function company( args, context ) {
|
||||
const company = new Company( context.graphQLContext.companyId );
|
||||
return company;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Mutations
|
||||
//////////////////////////////////////////////
|
||||
|
||||
module.exports = {
|
||||
account,
|
||||
profile,
|
||||
company
|
||||
};
|
||||
@@ -0,0 +1,88 @@
|
||||
type Query {
|
||||
account : Account!
|
||||
profile : User!
|
||||
company : Company!
|
||||
}
|
||||
|
||||
scalar DateTime
|
||||
|
||||
type Session {
|
||||
token : String!
|
||||
expiration : DateTime!
|
||||
}
|
||||
|
||||
type Account {
|
||||
user : User!
|
||||
|
||||
sessions( limit: Int , offset : Int ) : [Session]!
|
||||
sessionsCount : Int!
|
||||
}
|
||||
|
||||
type LocationCategory{
|
||||
id : Int!
|
||||
category : String!
|
||||
}
|
||||
|
||||
type Location{
|
||||
id : Int!
|
||||
company : Company!
|
||||
type : String!
|
||||
state : String!
|
||||
city : String!
|
||||
country : String!
|
||||
zipcode : String!
|
||||
address_line1 : String!
|
||||
address_line2 : String
|
||||
|
||||
categories : [LocationCategory]!
|
||||
categoriesCount : Int!
|
||||
}
|
||||
|
||||
type TruckType{
|
||||
id : Int!
|
||||
category : String!
|
||||
}
|
||||
|
||||
type CompanyCategory{
|
||||
id : Int!
|
||||
category : String!
|
||||
}
|
||||
|
||||
type Company {
|
||||
id : Int!
|
||||
owner : User!
|
||||
type : String!
|
||||
is_hidden : Boolean!
|
||||
is_active : Boolean!
|
||||
|
||||
name : String!
|
||||
description : String
|
||||
|
||||
createdAt : DateTime!
|
||||
|
||||
locations( limit: Int , offset : Int ) : [Location]!
|
||||
locationsCount : Int!
|
||||
|
||||
categories : [LocationCategory]!
|
||||
categoriesCount : Int!
|
||||
|
||||
truck_types : [TruckType]!
|
||||
truck_typesCount : Int!
|
||||
}
|
||||
|
||||
type User {
|
||||
id : Int!
|
||||
company : Company
|
||||
phone : String
|
||||
|
||||
email : String!
|
||||
name : String!
|
||||
last_name : String!
|
||||
job_role : String!
|
||||
permissions : String!
|
||||
createdAt : DateTime!
|
||||
is_active : Boolean!
|
||||
|
||||
locations( limit: Int , offset : Int ) : [Location]!
|
||||
locationsCount : Int!
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
const { buildSchema } = require('graphql');
|
||||
|
||||
const schema = fs.readFileSync(join(__dirname, './schema.graphql'), 'utf8');
|
||||
|
||||
module.exports = buildSchema( schema );
|
||||
26
v2/server/src/Apps/PrivateResources/Controller/index.js
Normal file
26
v2/server/src/Apps/PrivateResources/Controller/index.js
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
const router = require('express').Router();
|
||||
|
||||
const { createHandler } = require("graphql-http/lib/use/express");
|
||||
|
||||
/// Include graphql schema and resolvers
|
||||
const schemaDescription = require('./graphql/schema.js');
|
||||
const schemaResolvers = require('./graphql/resolvers.js');
|
||||
|
||||
router.get('/test', async (req, res) => {
|
||||
console.log( req.graphQLContext );
|
||||
res.status(200).send({
|
||||
msg : "It is alive!"
|
||||
});
|
||||
} );
|
||||
|
||||
router.post( '/graphql',
|
||||
createHandler({
|
||||
schema: schemaDescription,
|
||||
rootValue : schemaResolvers,
|
||||
context: async (req, params) => { return { graphQLContext : req.raw.graphQLContext }; },
|
||||
graphiql: true
|
||||
})
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user