Vulcan/packages/framework-demo/lib/schema.js

83 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-11-26 11:17:01 +09:00
/*
A SimpleSchema-compatible JSON schema
*/
import Telescope from 'meteor/nova:lib';
import Users from 'meteor/nova:users';
// define schema
const schema = {
_id: {
type: String,
optional: true,
viewableIf: ['anonymous'],
},
name: {
label: 'Name',
type: String,
viewableIf: ['anonymous'],
2016-11-29 11:35:20 +09:00
insertableIf: ['default'],
editableIf: ['default'],
},
createdAt: {
type: Date,
viewableIf: ['anonymous'],
autoValue: (documentOrModifier) => {
if (documentOrModifier && !documentOrModifier.$set) return new Date() // if this is an insert, set createdAt to current timestamp
}
},
year: {
label: 'Year',
type: String,
optional: true,
viewableIf: ['anonymous'],
2016-11-29 11:35:20 +09:00
insertableIf: ['default'],
editableIf: ['default'],
},
review: {
label: 'Review',
type: String,
control: "textarea",
viewableIf: ['anonymous'],
2016-11-29 11:35:20 +09:00
insertableIf: ['default'],
editableIf: ['default']
},
privateComments: {
label: 'Private Comments',
type: String,
optional: true,
control: "textarea",
viewableIf: Users.owns,
2016-11-29 11:35:20 +09:00
insertableIf: ['default'],
editableIf: ['default']
},
userId: {
type: String,
optional: true,
viewableIf: ['anonymous'],
resolveAs: 'user: User',
}
};
export default schema;
const termsSchema = `
input Terms {
view: String
userId: String
cat: String
date: String
after: String
before: String
enableCache: Boolean
listId: String
query: String # search query
postId: String
}
`;
Telescope.graphQL.addSchema(termsSchema);