Move query fields to live alongside query types

This commit is contained in:
Brian Beck 2016-11-26 19:19:18 -08:00
parent e3f8c805a0
commit 5f0710e353
5 changed files with 40 additions and 24 deletions

View file

@ -50,7 +50,7 @@ function browseQuery (connectionType, args) {
}
}
export default new GraphQLObjectType({
export const BrowseQuery = new GraphQLObjectType({
name: 'BrowseQuery',
description: `A query for all MusicBrainz entities directly linked to another
entity.`,
@ -118,3 +118,13 @@ release, but is not included in the credits for the release itself.`
})
}
})
export const browseField = {
type: BrowseQuery,
description: 'Browse all MusicBrainz entities directly linked to another entity.',
// We only have work to do once we know what entity types are being requested,
// so this can just resolve to an empty object.
resolve: () => ({})
}
export default BrowseQuery

View file

@ -1,3 +1,3 @@
export { default as LookupQuery } from './lookup'
export { default as BrowseQuery } from './browse'
export { default as SearchQuery } from './search'
export { LookupQuery, lookupField } from './lookup'
export { BrowseQuery, browseField } from './browse'
export { SearchQuery, searchField } from './search'

View file

@ -26,7 +26,7 @@ function lookupQuery (entity) {
}
}
export default new GraphQLObjectType({
export const LookupQuery = new GraphQLObjectType({
name: 'LookupQuery',
description: 'A lookup of an individual MusicBrainz entity by its MBID.',
fields: {
@ -44,3 +44,13 @@ export default new GraphQLObjectType({
work: lookupQuery(Work)
}
})
export const lookupField = {
type: LookupQuery,
description: 'Perform a lookup of a MusicBrainz entity by its MBID.',
// We only have work to do once we know what entity types are being requested,
// so this can just resolve to an empty object.
resolve: () => ({})
}
export default LookupQuery

View file

@ -26,7 +26,7 @@ function searchQuery (connectionType) {
}
}
export default new GraphQLObjectType({
export const SearchQuery = new GraphQLObjectType({
name: 'SearchQuery',
description: 'A search for MusicBrainz entities using Lucene query syntax.',
fields: {
@ -40,3 +40,13 @@ export default new GraphQLObjectType({
works: searchQuery(WorkConnection)
}
})
export const searchField = {
type: SearchQuery,
description: 'Search for MusicBrainz entities using Lucene query syntax.',
// We only have work to do once we know what entity types are being requested,
// so this can just resolve to an empty object.
resolve: () => ({})
}
export default SearchQuery

View file

@ -1,5 +1,5 @@
import { GraphQLSchema, GraphQLObjectType } from 'graphql'
import { LookupQuery, BrowseQuery, SearchQuery } from './queries'
import { lookupField, browseField, searchField } from './queries'
import { nodeField } from './types/node'
export default new GraphQLSchema({
@ -9,23 +9,9 @@ export default new GraphQLSchema({
requests can be made.`,
fields: () => ({
node: nodeField,
lookup: {
type: LookupQuery,
description: 'Perform a lookup of a MusicBrainz entity by its MBID.',
resolve: () => ({})
},
browse: {
type: BrowseQuery,
description: `Browse all MusicBrainz entities directly linked to another
entity.`,
resolve: () => ({})
},
search: {
type: SearchQuery,
description: `Search for MusicBrainz entities using Lucene query
syntax.`,
resolve: () => ({})
}
lookup: lookupField,
browse: browseField,
search: searchField
})
})
})