2018-06-04 11:22:49 +09:00
|
|
|
/* ------------------------------------- Main Type ------------------------------------- */
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
/*
|
|
|
|
|
|
|
|
The main type
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
type Movie{
|
|
|
|
_id: String
|
|
|
|
title: String
|
|
|
|
description: String
|
|
|
|
createdAt: Date
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
export const mainTypeTemplate = ({ typeName, description, interfaces }) =>
|
|
|
|
`# ${description}
|
|
|
|
type ${typeName} ${interfaces.length ? `implements ${interfaces.join(`, `)} ` : ''}{
|
2018-06-04 15:45:13 +09:00
|
|
|
# TODO: generate fields and their type from JavaScript schema
|
2018-06-04 11:22:49 +09:00
|
|
|
}
|
2018-06-04 15:45:13 +09:00
|
|
|
`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/* ------------------------------------- Selector Types ------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
The selector type is used to query for one or more documents
|
|
|
|
|
2018-06-04 11:22:49 +09:00
|
|
|
type MovieSelectorInput {
|
2018-06-04 15:45:13 +09:00
|
|
|
AND: [MovieSelectorInput]
|
|
|
|
OR: [MovieSelectorInput]
|
|
|
|
id: String
|
|
|
|
id_not: String
|
|
|
|
id_in: [String!]
|
|
|
|
id_not_in: [String!]
|
|
|
|
...
|
|
|
|
name: String
|
|
|
|
name_not: String
|
|
|
|
name_in: [String!]
|
|
|
|
name_not_in: [String!]
|
|
|
|
...
|
2018-06-04 11:22:49 +09:00
|
|
|
}
|
|
|
|
|
2018-06-04 15:45:13 +09:00
|
|
|
see https://www.opencrud.org/#sec-Data-types
|
2018-06-04 11:22:49 +09:00
|
|
|
|
2018-06-04 15:45:13 +09:00
|
|
|
*/
|
|
|
|
export const selectorInputTemplate = ({ typeName }) =>
|
2018-06-04 11:22:49 +09:00
|
|
|
`
|
2018-06-04 15:45:13 +09:00
|
|
|
# TODO: get fields that can be used as part of a selector
|
|
|
|
`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
The unique selector type is used to query for exactly one document
|
|
|
|
|
2018-06-04 11:22:49 +09:00
|
|
|
type MovieSelectorUniqueInput {
|
|
|
|
_id: String
|
2018-06-04 15:45:13 +09:00
|
|
|
slug: String
|
2018-06-04 11:22:49 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const selectorUniqueInputTemplate = ({ typeName }) =>
|
2018-06-04 11:22:49 +09:00
|
|
|
`
|
2018-06-04 15:45:13 +09:00
|
|
|
# TODO: get fields that can be used as part of a selector
|
|
|
|
`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
The orderBy type defines which fields a query can be ordered by
|
|
|
|
|
2018-06-04 15:45:13 +09:00
|
|
|
enum MovieOrderByInput {
|
|
|
|
title
|
|
|
|
createdAt
|
|
|
|
}
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const orderByInputTemplate = ({ typeName }) =>
|
|
|
|
`
|
|
|
|
# TODO: get fields that can be ordered
|
|
|
|
`;
|
|
|
|
|
|
|
|
/* ------------------------------------- Query Types ------------------------------------- */
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
A query for a single document
|
|
|
|
|
2018-06-04 15:45:13 +09:00
|
|
|
movie(input: SingleMovieInput) : SingleMovieOutput
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const singleQueryTemplate = ({ typeName }) => `${typeName}(input: Single${typeName}Input): Single${typeName}Output`;
|
|
|
|
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
A query for multiple documents
|
|
|
|
|
2018-06-04 15:45:13 +09:00
|
|
|
movies(input: MultiMovieInput) : MultiMovieOutput
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const multiQueryTemplate = ({ typeName }) => `${typeName}s(input: Multi${typeName}Input): Multi${typeName}Output`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/* ------------------------------------- Query Input Types ------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
The argument type when querying for multiple documents
|
|
|
|
|
2018-06-04 15:45:13 +09:00
|
|
|
type MultiMovieInput {
|
2018-06-04 11:22:49 +09:00
|
|
|
terms: JSON
|
|
|
|
offset: Int
|
|
|
|
limit: Int
|
|
|
|
enableCache: Boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const multiInputTemplate = ({ typeName }) =>
|
|
|
|
`type Multi${typeName}Input {
|
2018-06-04 11:22:49 +09:00
|
|
|
# A JSON object that contains the query terms used to fetch data
|
|
|
|
terms: JSON,
|
|
|
|
# How much to offset the results by
|
|
|
|
offset: Int,
|
|
|
|
# A limit for the query
|
|
|
|
limit: Int,
|
|
|
|
# Whether to enable caching for this query
|
|
|
|
enableCache: Boolean
|
2018-06-04 15:45:13 +09:00
|
|
|
# OpenCRUD fields
|
|
|
|
where: ${typeName}SelectorInput
|
|
|
|
orderBy: ${typeName}OrderByInput
|
|
|
|
skip: Int
|
|
|
|
after: String
|
|
|
|
before: String
|
|
|
|
first: Int
|
|
|
|
last: Int
|
|
|
|
}`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
The argument type when querying for a single document
|
|
|
|
|
2018-06-04 11:22:49 +09:00
|
|
|
type SingleMovieInput {
|
|
|
|
documentId: String
|
|
|
|
slug: String
|
|
|
|
enableCache: Boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const singleInputTemplate = ({ typeName }) =>
|
2018-06-04 11:22:49 +09:00
|
|
|
`type Single${typeName}Input {
|
|
|
|
# The document's unique ID
|
|
|
|
documentId: String,
|
|
|
|
# A unique slug identifying the document
|
|
|
|
slug: String,
|
|
|
|
# Whether to enable caching for this query
|
|
|
|
enableCache: Boolean
|
2018-06-04 15:45:13 +09:00
|
|
|
}`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/* ------------------------------------- Query Output Types ------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
The type for the return value when querying for multiple documents
|
|
|
|
|
2018-06-04 15:45:13 +09:00
|
|
|
type MultiMovieOuput{
|
2018-06-04 11:22:49 +09:00
|
|
|
data: [Movie]
|
2018-06-04 15:45:13 +09:00
|
|
|
totalCount: Int
|
2018-06-04 11:22:49 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const MultiOutputTemplate = ({ typeName }) =>
|
|
|
|
`type Multi${typeName}Output{
|
2018-06-04 11:22:49 +09:00
|
|
|
data: [${typeName}]
|
2018-06-04 11:57:53 +09:00
|
|
|
totalCount: Int
|
2018-06-04 15:45:13 +09:00
|
|
|
}`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
The type for the return value when querying for a single document
|
|
|
|
|
2018-06-04 11:22:49 +09:00
|
|
|
type SingleMovieOuput{
|
|
|
|
data: Movie
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const singleOutputTemplate = ({ typeName }) =>
|
2018-06-04 11:22:49 +09:00
|
|
|
`type Single${typeName}Output{
|
|
|
|
data: ${typeName}
|
2018-06-04 15:45:13 +09:00
|
|
|
}`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/* ------------------------------------- Mutation Types ------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
Mutation for creating a new document
|
|
|
|
|
2018-06-04 15:45:13 +09:00
|
|
|
createMovie(input: CreateMovieInput) : MovieOutput
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const createMutationTemplate = ({ typeName }) =>
|
|
|
|
`create${typeName}(input: Create${typeName}Input) : Create${typeName}Output`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
Mutation for updating an existing document
|
|
|
|
|
2018-06-04 15:45:13 +09:00
|
|
|
updateMovie(input: UpdateMovieInput) : MovieOutput
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const updateMutationTemplate = ({ typeName }) =>
|
|
|
|
`update${typeName}(input: Update${typeName}Input) : Update${typeName}Output`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
Mutation for updating an existing document; or creating it if it doesn't exist yet
|
|
|
|
|
2018-06-04 15:45:13 +09:00
|
|
|
upsertMovie(input: UpsertMovieInput) : MovieOutput
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const upsertMutationTemplate = ({ typeName }) =>
|
|
|
|
`upsert${typeName}(input: Upsert${typeName}Input) : Upsert${typeName}Output`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
Mutation for deleting an existing document
|
|
|
|
|
2018-06-04 15:45:13 +09:00
|
|
|
deleteMovie(input: DeleteMovieInput) : MovieOutput
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const deleteMutationTemplate = ({ typeName }) =>
|
|
|
|
`delete${typeName}(input: Delete${typeName}Input) : Delete${typeName}Output`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/* ------------------------------------- Mutation Input Types ------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
Type for create mutation input argument
|
|
|
|
|
2018-06-04 11:22:49 +09:00
|
|
|
type CreateMovieInput {
|
|
|
|
data: CreateMovieDataInput!
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
export const createInputTemplate = ({ typeName }) =>
|
|
|
|
`type Create${typeName}Input{
|
|
|
|
data: Create${typeName}DataInput!
|
2018-06-04 15:45:13 +09:00
|
|
|
}`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
Type for update mutation input argument
|
|
|
|
|
2018-06-04 11:22:49 +09:00
|
|
|
type UpdateMovieInput {
|
|
|
|
selector: MovieSelectorUniqueInput!
|
|
|
|
data: UpdateMovieDataInput!
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const updateInputTemplate = ({ typeName }) =>
|
2018-06-04 11:22:49 +09:00
|
|
|
`type Update${typeName}Input{
|
|
|
|
selector: ${typeName}SelectorUniqueInput!
|
|
|
|
data: Update${typeName}DataInput!
|
2018-06-04 15:45:13 +09:00
|
|
|
}`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
Type for upsert mutation input argument
|
|
|
|
|
2018-06-04 11:22:49 +09:00
|
|
|
Note: upsertInputTemplate uses same data type as updateInputTemplate
|
|
|
|
|
|
|
|
type UpsertMovieInput {
|
|
|
|
selector: MovieSelectorUniqueInput!
|
|
|
|
data: UpdateMovieDataInput!
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
export const upsertInputTemplate = ({ typeName }) =>
|
|
|
|
`type Upsert${typeName}Input{
|
|
|
|
selector: ${typeName}SelectorUniqueInput!
|
|
|
|
data: Update${typeName}DataInput!
|
2018-06-04 15:45:13 +09:00
|
|
|
}`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
Type for delete mutation input argument
|
|
|
|
|
2018-06-04 11:22:49 +09:00
|
|
|
type DeleteMovieInput {
|
|
|
|
selector: MovieSelectorUniqueInput!
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
export const deleteInputTemplate = ({ typeName }) =>
|
|
|
|
`type Delete${typeName}Input{
|
|
|
|
selector: ${typeName}SelectorUniqueInput!
|
2018-06-04 15:45:13 +09:00
|
|
|
}`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
Type for the create mutation input argument's data property
|
|
|
|
|
2018-06-04 11:22:49 +09:00
|
|
|
type CreateMovieDataInput {
|
|
|
|
title: String
|
|
|
|
description: String
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const createDataInputTemplate = ({ typeName }) =>
|
2018-06-04 11:22:49 +09:00
|
|
|
`
|
2018-06-04 17:59:18 +09:00
|
|
|
# TODO: get fields that are insertable
|
2018-06-04 15:45:13 +09:00
|
|
|
`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
Type for the update mutation input argument's data property
|
|
|
|
|
2018-06-04 11:22:49 +09:00
|
|
|
type UpdateMovieDataInput {
|
|
|
|
title: String
|
|
|
|
description: String
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const updateDataInputTemplate = ({ typeName }) =>
|
2018-06-04 11:22:49 +09:00
|
|
|
`
|
2018-06-04 17:59:18 +09:00
|
|
|
# TODO: get fields that are editable
|
2018-06-04 15:45:13 +09:00
|
|
|
`;
|
2018-06-04 11:22:49 +09:00
|
|
|
|
2018-06-04 15:45:13 +09:00
|
|
|
/* ------------------------------------- Mutation Output Type ------------------------------------- */
|
2018-06-04 11:22:49 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
2018-06-04 17:59:18 +09:00
|
|
|
Type for the return value of all mutations
|
|
|
|
|
2018-06-04 15:45:13 +09:00
|
|
|
type MovieOutput {
|
2018-06-04 11:22:49 +09:00
|
|
|
data: Movie
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
2018-06-04 15:45:13 +09:00
|
|
|
export const mutationOutputTemplate = ({ typeName }) =>
|
|
|
|
`type ${typeName}Output{
|
2018-06-04 11:22:49 +09:00
|
|
|
data: ${typeName}
|
2018-06-04 15:45:13 +09:00
|
|
|
}`;
|