mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Coerce undefinedToNull in embed resolver
This commit is contained in:
parent
c5789cbf90
commit
4ee20d4e7e
9
backend/src/schema/helpers.js
Normal file
9
backend/src/schema/helpers.js
Normal file
@ -0,0 +1,9 @@
|
||||
export const undefinedToNull = list => {
|
||||
const resolvers = {}
|
||||
list.forEach(key => {
|
||||
resolvers[key] = async (parent, params, context, resolveInfo) => {
|
||||
return typeof parent[key] === 'undefined' ? null : parent[key]
|
||||
}
|
||||
})
|
||||
return resolvers
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
import scrape from './embeds/scraper.js'
|
||||
import { undefinedToNull } from '../helpers'
|
||||
|
||||
export default {
|
||||
Query: {
|
||||
@ -6,4 +7,23 @@ export default {
|
||||
return scrape(url)
|
||||
},
|
||||
},
|
||||
Embed: {
|
||||
...undefinedToNull([
|
||||
'type',
|
||||
'title',
|
||||
'author',
|
||||
'publisher',
|
||||
'date',
|
||||
'description',
|
||||
'url',
|
||||
'image',
|
||||
'audio',
|
||||
'video',
|
||||
'lang',
|
||||
'html',
|
||||
]),
|
||||
sources: async (parent, params, context, resolveInfo) => {
|
||||
return typeof parent.sources === 'undefined' ? [] : parent.sources
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -95,23 +95,8 @@ export default async function scrape(url) {
|
||||
throw new ApolloError('Not found', 'NOT_FOUND')
|
||||
}
|
||||
|
||||
const defaults = {
|
||||
type: 'link',
|
||||
title: null,
|
||||
author: null,
|
||||
publisher: null,
|
||||
date: null,
|
||||
description: null,
|
||||
url: null,
|
||||
image: null,
|
||||
audio: null,
|
||||
video: null,
|
||||
lang: null,
|
||||
html: null,
|
||||
}
|
||||
|
||||
return {
|
||||
...defaults,
|
||||
type: 'link',
|
||||
...output,
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ import { neo4jgraphql } from 'neo4j-graphql-js'
|
||||
import fileUpload from './fileUpload'
|
||||
import { neode } from '../../bootstrap/neo4j'
|
||||
import { UserInputError } from 'apollo-server'
|
||||
import { undefinedToNull } from '../helpers'
|
||||
|
||||
const instance = neode()
|
||||
|
||||
@ -36,16 +37,6 @@ const count = obj => {
|
||||
return resolvers
|
||||
}
|
||||
|
||||
const undefinedToNull = list => {
|
||||
const resolvers = {}
|
||||
list.forEach(key => {
|
||||
resolvers[key] = async (parent, params, context, resolveInfo) => {
|
||||
return typeof parent[key] === 'undefined' ? null : parent[key]
|
||||
}
|
||||
})
|
||||
return resolvers
|
||||
}
|
||||
|
||||
export const hasMany = obj => {
|
||||
const resolvers = {}
|
||||
for (const [key, connection] of Object.entries(obj)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user