mirror of
https://github.com/BradNut/graphbrainz
synced 2025-09-08 17:40:32 +00:00
Comments and docs
This commit is contained in:
parent
c7527ad993
commit
742b70f834
5 changed files with 21 additions and 8 deletions
|
|
@ -5,13 +5,16 @@ import { toPlural } from './types/helpers'
|
||||||
const debug = require('debug')('graphbrainz:loaders')
|
const debug = require('debug')('graphbrainz:loaders')
|
||||||
|
|
||||||
export default function createLoaders (client) {
|
export default function createLoaders (client) {
|
||||||
|
// All loaders share a single LRU cache that will remember 8192 responses,
|
||||||
|
// each cached for 1 day.
|
||||||
const cache = LRUCache({
|
const cache = LRUCache({
|
||||||
max: 8192,
|
max: 8192,
|
||||||
maxAge: 24 * 60 * 60 * 1000, // 1 day.
|
maxAge: 24 * 60 * 60 * 1000,
|
||||||
dispose (key) {
|
dispose (key) {
|
||||||
debug(`Removed '${key}' from cache.`)
|
debug(`Removed '${key}' from cache.`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
// Make the cache Map-like.
|
||||||
cache.delete = cache.del
|
cache.delete = cache.del
|
||||||
cache.clear = cache.reset
|
cache.clear = cache.reset
|
||||||
|
|
||||||
|
|
@ -20,6 +23,8 @@ export default function createLoaders (client) {
|
||||||
const [ entityType, id, params ] = key
|
const [ entityType, id, params ] = key
|
||||||
return client.lookup(entityType, id, params).then(entity => {
|
return client.lookup(entityType, id, params).then(entity => {
|
||||||
if (entity) {
|
if (entity) {
|
||||||
|
// Store the entity type so we can determine what type of object this
|
||||||
|
// is elsewhere in the code.
|
||||||
entity.entityType = entityType
|
entity.entityType = entityType
|
||||||
}
|
}
|
||||||
return entity
|
return entity
|
||||||
|
|
@ -35,6 +40,8 @@ export default function createLoaders (client) {
|
||||||
const [ entityType, params ] = key
|
const [ entityType, params ] = key
|
||||||
return client.browse(entityType, params).then(list => {
|
return client.browse(entityType, params).then(list => {
|
||||||
list[toPlural(entityType)].forEach(entity => {
|
list[toPlural(entityType)].forEach(entity => {
|
||||||
|
// Store the entity type so we can determine what type of object this
|
||||||
|
// is elsewhere in the code.
|
||||||
entity.entityType = entityType
|
entity.entityType = entityType
|
||||||
})
|
})
|
||||||
return list
|
return list
|
||||||
|
|
@ -50,6 +57,8 @@ export default function createLoaders (client) {
|
||||||
const [ entityType, query, params ] = key
|
const [ entityType, query, params ] = key
|
||||||
return client.search(entityType, query, params).then(list => {
|
return client.search(entityType, query, params).then(list => {
|
||||||
list[toPlural(entityType)].forEach(entity => {
|
list[toPlural(entityType)].forEach(entity => {
|
||||||
|
// Store the entity type so we can determine what type of object this
|
||||||
|
// is elsewhere in the code.
|
||||||
entity.entityType = entityType
|
entity.entityType = entityType
|
||||||
})
|
})
|
||||||
return list
|
return list
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,8 @@ export function browseResolver () {
|
||||||
params.type = params.type.map(formatValue)
|
params.type = params.type.map(formatValue)
|
||||||
params.status = params.status.map(formatValue)
|
params.status = params.status.map(formatValue)
|
||||||
return loaders.browse.load([singularName, params]).then(list => {
|
return loaders.browse.load([singularName, params]).then(list => {
|
||||||
|
// Grab the list, offet, and count from the response and use them to build
|
||||||
|
// a Relay connection object.
|
||||||
const {
|
const {
|
||||||
[pluralName]: arraySlice,
|
[pluralName]: arraySlice,
|
||||||
[`${singularName}-offset`]: sliceStart,
|
[`${singularName}-offset`]: sliceStart,
|
||||||
|
|
@ -99,6 +101,7 @@ export function searchResolver () {
|
||||||
export function relationshipResolver () {
|
export function relationshipResolver () {
|
||||||
return (source, args, context, info) => {
|
return (source, args, context, info) => {
|
||||||
const targetType = toDashed(toSingular(info.fieldName)).replace('-', '_')
|
const targetType = toDashed(toSingular(info.fieldName)).replace('-', '_')
|
||||||
|
// There's no way to filter these at the API level, so do it here.
|
||||||
const relationships = source.filter(rel => {
|
const relationships = source.filter(rel => {
|
||||||
if (rel['target-type'] !== targetType) {
|
if (rel['target-type'] !== targetType) {
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,8 @@ record company. (Most releases will fit into this category.)`,
|
||||||
PROMOTION: {
|
PROMOTION: {
|
||||||
name: 'Promotion',
|
name: 'Promotion',
|
||||||
description: `A giveaway release or a release intended to promote an
|
description: `A giveaway release or a release intended to promote an
|
||||||
upcoming official release. (e.g. prerelease albums or releases included with a
|
upcoming official release, e.g. prerelease albums or releases included with a
|
||||||
magazine)`,
|
magazine.`,
|
||||||
value: 'Promotion'
|
value: 'Promotion'
|
||||||
},
|
},
|
||||||
BOOTLEG: {
|
BOOTLEG: {
|
||||||
|
|
@ -116,7 +116,7 @@ by one or more artists.`,
|
||||||
SOUNDTRACK: {
|
SOUNDTRACK: {
|
||||||
name: 'Soundtrack',
|
name: 'Soundtrack',
|
||||||
description: `A soundtrack is the musical score to a movie, TV series,
|
description: `A soundtrack is the musical score to a movie, TV series,
|
||||||
stage show, computer game etc.`,
|
stage show, computer game, etc.`,
|
||||||
value: 'Soundtrack'
|
value: 'Soundtrack'
|
||||||
},
|
},
|
||||||
SPOKENWORD: {
|
SPOKENWORD: {
|
||||||
|
|
@ -167,7 +167,7 @@ While mixtapes are generally DJ-mixed, they are distinct from commercial DJ
|
||||||
mixes (which are usually deemed compilations) and are defined by having a
|
mixes (which are usually deemed compilations) and are defined by having a
|
||||||
significant proportion of new material, including original production or
|
significant proportion of new material, including original production or
|
||||||
original vocals over top of other artists’ instrumentals. They are distinct from
|
original vocals over top of other artists’ instrumentals. They are distinct from
|
||||||
demos in that they are designed for release directly to the public and fans; not
|
demos in that they are designed for release directly to the public and fans, not
|
||||||
to labels.`,
|
to labels.`,
|
||||||
value: 'Mixtape/Street'
|
value: 'Mixtape/Street'
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -58,10 +58,11 @@ export function fieldWithID (name, config = {}) {
|
||||||
const isPlural = config.type instanceof GraphQLList
|
const isPlural = config.type instanceof GraphQLList
|
||||||
const singularName = isPlural ? toSingular(name) : name
|
const singularName = isPlural ? toSingular(name) : name
|
||||||
const idName = isPlural ? `${singularName}IDs` : `${name}ID`
|
const idName = isPlural ? `${singularName}IDs` : `${name}ID`
|
||||||
|
const s = isPlural ? 's' : ''
|
||||||
const idConfig = {
|
const idConfig = {
|
||||||
type: isPlural ? new GraphQLList(MBID) : MBID,
|
type: isPlural ? new GraphQLList(MBID) : MBID,
|
||||||
description: `The MBID${isPlural ? 's' : ''} associated with the
|
description: `The MBID${s} associated with the value${s} of the \`${name}\`
|
||||||
value${isPlural ? 's' : ''} of the \`${name}\` field.`,
|
field.`,
|
||||||
resolve: getHyphenated
|
resolve: getHyphenated
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import Area from './area'
|
||||||
|
|
||||||
export default new GraphQLObjectType({
|
export default new GraphQLObjectType({
|
||||||
name: 'ReleaseEvent',
|
name: 'ReleaseEvent',
|
||||||
description: `Date on which a release was released in a country/region with a
|
description: `Date on which a release was issued in a country/region with a
|
||||||
particular label, catalog number, barcode, and what release format was used.`,
|
particular label, catalog number, barcode, and what release format was used.`,
|
||||||
fields: () => ({
|
fields: () => ({
|
||||||
area: { type: Area },
|
area: { type: Area },
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue