mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-03-01 12:44:37 +00:00
Example code of lecture #10
This commit is contained in:
parent
6b049b52db
commit
8c9afe3139
21
backend/src/middleware/demoMiddleware.js
Normal file
21
backend/src/middleware/demoMiddleware.js
Normal file
@ -0,0 +1,21 @@
|
||||
export default {
|
||||
Query: {
|
||||
listCategories: async (resolve, parent, args, context, resolveInfo) => {
|
||||
console.log('Query.listCategories')
|
||||
const categories = await resolve(parent, args, context, resolveInfo)
|
||||
console.log('resolved categories:', categories)
|
||||
return categories
|
||||
},
|
||||
},
|
||||
Category: {
|
||||
slug: async (resolve, parent, args, context, resolveInfo) => {
|
||||
console.log('Category.slug')
|
||||
console.log('parent:', parent)
|
||||
const { user } = context
|
||||
if (!user) return 'censored'
|
||||
const slug = await resolve(parent, args, context, resolveInfo)
|
||||
console.log('resolved slug:', slug)
|
||||
return slug
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -15,6 +15,7 @@ import notifications from './notifications/notificationsMiddleware'
|
||||
import hashtags from './hashtags/hashtagsMiddleware'
|
||||
import email from './email/emailMiddleware'
|
||||
import sentry from './sentryMiddleware'
|
||||
import demoMiddleware from './demoMiddleware'
|
||||
|
||||
export default schema => {
|
||||
const middlewares = {
|
||||
@ -32,6 +33,7 @@ export default schema => {
|
||||
includedFields,
|
||||
orderBy,
|
||||
email,
|
||||
demoMiddleware,
|
||||
}
|
||||
|
||||
let order = [
|
||||
@ -49,6 +51,7 @@ export default schema => {
|
||||
'user',
|
||||
'includedFields',
|
||||
'orderBy',
|
||||
'demoMiddleware',
|
||||
]
|
||||
|
||||
// add permisions middleware at the first position (unless we're seeding)
|
||||
|
||||
@ -84,6 +84,7 @@ export default shield(
|
||||
{
|
||||
Query: {
|
||||
'*': deny,
|
||||
listCategories: allow,
|
||||
findPosts: allow,
|
||||
embed: allow,
|
||||
Category: allow,
|
||||
|
||||
34
backend/src/schema/resolvers/demo.js
Normal file
34
backend/src/schema/resolvers/demo.js
Normal file
@ -0,0 +1,34 @@
|
||||
export default {
|
||||
Query: {
|
||||
listCategories: () => [
|
||||
{
|
||||
name: 'Global Peace & Nonviolence',
|
||||
slug: 'global-peace-nonviolence',
|
||||
},
|
||||
{
|
||||
name: 'Human Rights & Justice',
|
||||
slug: 'human-rights-justice',
|
||||
},
|
||||
{
|
||||
name: 'Happiness & Values',
|
||||
slug: 'happiness-values',
|
||||
},
|
||||
{
|
||||
name: 'Economy & Finances',
|
||||
slug: 'economy-finances',
|
||||
},
|
||||
{
|
||||
name: 'Freedom of Speech',
|
||||
slug: 'freedom-of-speech',
|
||||
},
|
||||
{
|
||||
name: 'Consumption & Sustainability',
|
||||
slug: 'consumption-sustainability',
|
||||
},
|
||||
{
|
||||
name: 'Animal Protection',
|
||||
slug: 'animal-protection',
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
type Query {
|
||||
listCategories: [Category]
|
||||
isLoggedIn: Boolean!
|
||||
# Get the currently logged in User based on the given JWT Token
|
||||
currentUser: User
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user