feat: GraphQL Date scalar
This commit is contained in:
parent
7e1cb3d171
commit
1405b822f4
@ -81,9 +81,9 @@ module.exports = (port, spinner) => {
|
|||||||
() => {
|
() => {
|
||||||
const semver = require('semver')
|
const semver = require('semver')
|
||||||
if (!semver.satisfies(semver.clean(process.version), '>=6.9.0')) {
|
if (!semver.satisfies(semver.clean(process.version), '>=6.9.0')) {
|
||||||
throw new Error('Node.js version is too old. Minimum is v6.6.0.')
|
throw new Error('Node.js version is too old. Minimum is v6.11.1.')
|
||||||
}
|
}
|
||||||
return 'Node.js ' + process.version + ' detected. Minimum is v6.9.0.'
|
return 'Node.js ' + process.version + ' detected.'
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
return Promise.try(() => {
|
return Promise.try(() => {
|
||||||
@ -110,10 +110,10 @@ module.exports = (port, spinner) => {
|
|||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
if (os.totalmem() < 1000 * 1000 * 768) {
|
if (os.totalmem() < 1000 * 1000 * 512) {
|
||||||
throw new Error('Not enough memory. Minimum is 768 MB.')
|
throw new Error('Not enough memory. Minimum is 512 MB.')
|
||||||
}
|
}
|
||||||
return _.round(os.totalmem() / (1024 * 1024)) + ' MB of system memory available. Minimum is 768 MB.'
|
return _.round(os.totalmem() / (1024 * 1024)) + ' MB of system memory available. Minimum is 512 MB.'
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
let fs = require('fs')
|
let fs = require('fs')
|
||||||
|
@ -9,12 +9,14 @@ const _ = require('lodash')
|
|||||||
|
|
||||||
const typeDefs = fs.readFileSync(path.join(wiki.SERVERPATH, 'schemas/types.graphql'), 'utf8')
|
const typeDefs = fs.readFileSync(path.join(wiki.SERVERPATH, 'schemas/types.graphql'), 'utf8')
|
||||||
|
|
||||||
|
const DateScalar = require('../schemas/scalar-date')
|
||||||
const GroupResolvers = require('../schemas/resolvers-group')
|
const GroupResolvers = require('../schemas/resolvers-group')
|
||||||
const UserResolvers = require('../schemas/resolvers-user')
|
const UserResolvers = require('../schemas/resolvers-user')
|
||||||
|
|
||||||
const resolvers = _.merge(
|
const resolvers = _.merge(
|
||||||
GroupResolvers,
|
GroupResolvers,
|
||||||
UserResolvers
|
UserResolvers,
|
||||||
|
DateScalar
|
||||||
)
|
)
|
||||||
|
|
||||||
const Schema = gqlTools.makeExecutableSchema({
|
const Schema = gqlTools.makeExecutableSchema({
|
||||||
|
22
server/schemas/scalar-date.js
Normal file
22
server/schemas/scalar-date.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const gql = require('graphql')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
Date: new gql.GraphQLScalarType({
|
||||||
|
name: 'Date',
|
||||||
|
description: 'ISO date-time string at UTC',
|
||||||
|
parseValue(value) {
|
||||||
|
return new Date(value)
|
||||||
|
},
|
||||||
|
serialize(value) {
|
||||||
|
return value.toISOString()
|
||||||
|
},
|
||||||
|
parseLiteral(ast) {
|
||||||
|
if (ast.kind !== gql.Kind.STRING) {
|
||||||
|
throw new TypeError('Date value must be an string!')
|
||||||
|
}
|
||||||
|
return new Date(ast.value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
@ -25,16 +25,16 @@ enum RightRole {
|
|||||||
|
|
||||||
interface Base {
|
interface Base {
|
||||||
id: Int!
|
id: Int!
|
||||||
createdOn: Date
|
createdAt: Date
|
||||||
updatedOn: Date
|
updatedAt: Date
|
||||||
}
|
}
|
||||||
|
|
||||||
# TYPES
|
# TYPES
|
||||||
|
|
||||||
type Comment implements Base {
|
type Comment implements Base {
|
||||||
id: Int!
|
id: Int!
|
||||||
createdOn: Date
|
createdAt: Date
|
||||||
updatedOn: Date
|
updatedAt: Date
|
||||||
content: String
|
content: String
|
||||||
document: Document!
|
document: Document!
|
||||||
author: User!
|
author: User!
|
||||||
@ -42,8 +42,8 @@ type Comment implements Base {
|
|||||||
|
|
||||||
type Document implements Base {
|
type Document implements Base {
|
||||||
id: Int!
|
id: Int!
|
||||||
createdOn: Date
|
createdAt: Date
|
||||||
updatedOn: Date
|
updatedAt: Date
|
||||||
path: String!
|
path: String!
|
||||||
title: String!
|
title: String!
|
||||||
subtitle: String
|
subtitle: String
|
||||||
@ -57,8 +57,8 @@ type Document implements Base {
|
|||||||
|
|
||||||
type File implements Base {
|
type File implements Base {
|
||||||
id: Int!
|
id: Int!
|
||||||
createdOn: Date
|
createdAt: Date
|
||||||
updatedOn: Date
|
updatedAt: Date
|
||||||
category: FileType!
|
category: FileType!
|
||||||
mime: String!
|
mime: String!
|
||||||
extra: String
|
extra: String
|
||||||
@ -70,15 +70,15 @@ type File implements Base {
|
|||||||
|
|
||||||
type Folder implements Base {
|
type Folder implements Base {
|
||||||
id: Int!
|
id: Int!
|
||||||
createdOn: Date
|
createdAt: Date
|
||||||
updatedOn: Date
|
updatedAt: Date
|
||||||
name: String!
|
name: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
type Group implements Base {
|
type Group implements Base {
|
||||||
id: Int!
|
id: Int!
|
||||||
createdOn: Date
|
createdAt: Date
|
||||||
updatedOn: Date
|
updatedAt: Date
|
||||||
name: String!
|
name: String!
|
||||||
users: [User]
|
users: [User]
|
||||||
rights: [Right]
|
rights: [Right]
|
||||||
@ -86,8 +86,8 @@ type Group implements Base {
|
|||||||
|
|
||||||
type Right implements Base {
|
type Right implements Base {
|
||||||
id: Int!
|
id: Int!
|
||||||
createdOn: Date
|
createdAt: Date
|
||||||
updatedOn: Date
|
updatedAt: Date
|
||||||
path: String!
|
path: String!
|
||||||
role: RightRole!
|
role: RightRole!
|
||||||
exact: Boolean!
|
exact: Boolean!
|
||||||
@ -96,8 +96,8 @@ type Right implements Base {
|
|||||||
|
|
||||||
type Setting implements Base {
|
type Setting implements Base {
|
||||||
id: Int!
|
id: Int!
|
||||||
createdOn: Date
|
createdAt: Date
|
||||||
updatedOn: Date
|
updatedAt: Date
|
||||||
key: String!
|
key: String!
|
||||||
config: String!
|
config: String!
|
||||||
}
|
}
|
||||||
@ -105,16 +105,16 @@ type Setting implements Base {
|
|||||||
# Tags are attached to one or more documents
|
# Tags are attached to one or more documents
|
||||||
type Tag implements Base {
|
type Tag implements Base {
|
||||||
id: Int!
|
id: Int!
|
||||||
createdOn: Date
|
createdAt: Date
|
||||||
updatedOn: Date
|
updatedAt: Date
|
||||||
key: String!
|
key: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
# A User
|
# A User
|
||||||
type User implements Base {
|
type User implements Base {
|
||||||
id: Int!
|
id: Int!
|
||||||
createdOn: Date
|
createdAt: Date
|
||||||
updatedOn: Date
|
updatedAt: Date
|
||||||
email: String!
|
email: String!
|
||||||
provider: String!
|
provider: String!
|
||||||
providerId: String
|
providerId: String
|
||||||
|
Loading…
Reference in New Issue
Block a user