Skip to content

Commit

Permalink
Merge pull request #16 from redwoodjs/pp-use-auto-schema-map
Browse files Browse the repository at this point in the history
Use auto mapping of schema definition to services.
  • Loading branch information
mojombo committed Jan 29, 2020
2 parents 01185a0 + bed7547 commit f9d7ecf
Show file tree
Hide file tree
Showing 9 changed files with 1,161 additions and 352 deletions.
4 changes: 2 additions & 2 deletions api/package.json
Expand Up @@ -4,11 +4,11 @@
"version": "0.0.0",
"dependencies": {
"@prisma/photon": "2.0.0-preview019",
"@redwoodjs/api": "^0.0.1-alpha.21"
"@redwoodjs/api": "^0.0.1-alpha.22"
},
"devDependencies": {
"prisma2": "2.0.0-preview019",
"@redwoodjs/dev-server": "^0.0.1-alpha.21"
"@redwoodjs/dev-server": "^0.0.1-alpha.22"
},
"scripts": {
"dev": "yarn dev-server",
Expand Down
13 changes: 8 additions & 5 deletions api/src/functions/graphql.js
@@ -1,9 +1,12 @@
import { server, makeMergedSchema } from '@redwoodjs/api'
import importAll from '@redwoodjs/core/dist/importAll.macro'
import { server, makeMergedSchema, makeServices } from '@redwoodjs/api'

import * as todo from 'src/graphql/todo'

const schema = makeMergedSchema([todo])
const schemas = importAll('api', 'graphql')
const services = importAll('api', 'services')

export const handler = server({
schema,
schema: makeMergedSchema({
schemas,
services: makeServices({ services }),
}),
}).createHandler()
38 changes: 0 additions & 38 deletions api/src/graphql/todo.js

This file was deleted.

17 changes: 17 additions & 0 deletions api/src/graphql/todos.js
@@ -0,0 +1,17 @@
export const schema = `
type Todo {
id: Int!
body: String!
status: String!
}
type Query {
todos: [Todo]
}
type Mutation {
createTodo(body: String!): Todo
updateTodoStatus(id: Int!, status: String!): Todo
renameTodo(id: Int!, body: String!): Todo
}
`
55 changes: 24 additions & 31 deletions api/src/services/todos.js
Expand Up @@ -2,37 +2,30 @@ import { Photon } from '@prisma/photon'

const photon = new Photon()

export const todos = {
all: () => {
return photon.todos.findMany()
},
export const todos = () => photon.todos.findMany()

// Create a new todo.
//
// body - The String body text.
//
// Returns a Todo object.
create: (body) => {
return photon.todos.create({ data: { body: body } })
},
// Create a new todo.
//
// body - The String body text.
//
// Returns a Todo object.
export const createTodo = ({ body }) =>
photon.todos.create({ data: { body: body } })

// Update the status of a todo.
//
// id - The id of the todo.
// status - The new status. One of 'on', 'off', 'loading'.
//
// Returns the updated Todo object.
updateStatus: (id, status) => {
return photon.todos.update({
data: { status },
where: { id },
})
},
// Update the status of a todo.
//
// id - The id of the todo.
// status - The new status. One of 'on', 'off', 'loading'.
//
// Returns the updated Todo object.
export const updateTodoStatus = ({ id, status }) =>
photon.todos.update({
data: { status },
where: { id },
})

rename: (id, body) => {
return photon.todos.update({
data: { body },
where: { id },
})
},
}
export const renameTodo = ({ id, body }) =>
photon.todos.update({
data: { body },
where: { id },
})
15 changes: 8 additions & 7 deletions babel.config.js
@@ -1,9 +1,10 @@
module.exports = {
presets: ["@babel/preset-react", "@babel/typescript"],
presets: ['@babel/preset-react', '@babel/typescript'],
plugins: [
["@babel/plugin-proposal-class-properties", { loose: true }],
["@babel/plugin-proposal-export-default-from"],
["@babel/plugin-proposal-object-rest-spread"],
["@babel/plugin-proposal-optional-chaining"]
]
};
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-export-default-from'],
['@babel/plugin-proposal-object-rest-spread'],
['@babel/plugin-proposal-optional-chaining'],
'macros',
],
}
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -8,9 +8,10 @@
"packages/**"
],
"devDependencies": {
"@redwoodjs/scripts": "^0.0.1-alpha.21",
"@redwoodjs/core": "^0.0.1-alpha.21",
"@redwoodjs/eslint-config": "^0.0.1-alpha.19"
"@redwoodjs/cli":"^0.0.1-alpha.22",
"@redwoodjs/scripts": "^0.0.1-alpha.22",
"@redwoodjs/core": "^0.0.1-alpha.22.0.1",
"@redwoodjs/eslint-config": "^0.0.1-alpha.22"
},
"eslintConfig": {
"extends": "@redwoodjs/eslint-config"
Expand Down
6 changes: 3 additions & 3 deletions web/package.json
Expand Up @@ -3,16 +3,16 @@
"name": "web",
"version": "0.0.0",
"dependencies": {
"@redwoodjs/web": "^0.0.1-alpha.21",
"@redwoodjs/router": "^0.0.1-alpha.21",
"@redwoodjs/web": "^0.0.1-alpha.22",
"@redwoodjs/router": "^0.0.1-alpha.22",
"prop-types": "^15.7.2",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-router-dom": "^5.1.2",
"styled-components": "^5.0.0"
},
"devDependencies": {
"@redwoodjs/scripts": "^0.0.1-alpha.21"
"@redwoodjs/scripts": "^0.0.1-alpha.22"
},
"scripts": {
"dev": "webpack-dev-server --config ./config/webpack.dev.js",
Expand Down

0 comments on commit f9d7ecf

Please sign in to comment.