-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: entities resolution * chore: fix test skip
- Loading branch information
1 parent
0eea5cf
commit 942faec
Showing
8 changed files
with
1,052 additions
and
717 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict' | ||
|
||
const schema = ` | ||
type Artist { | ||
id: ID | ||
firstName: String | ||
lastName: String | ||
profession: String | ||
} | ||
type Query { | ||
artists(ids: [ID!]!): [Artist] | ||
} | ||
` | ||
|
||
const data = { | ||
artists: null | ||
} | ||
|
||
function reset () { | ||
data.artists = { | ||
101: { | ||
id: 101, | ||
firstName: 'Christopher', | ||
lastName: 'Nolan', | ||
profession: 'Director' | ||
}, | ||
102: { | ||
id: 102, | ||
firstName: 'Roberto', | ||
lastName: 'Benigni', | ||
profession: 'Director' | ||
}, | ||
103: { | ||
id: 103, | ||
firstName: 'Brian', | ||
lastName: 'Molko', | ||
profession: 'Singer' | ||
} | ||
} | ||
} | ||
|
||
reset() | ||
|
||
const resolvers = { | ||
Query: { | ||
artists (_, { ids }) { | ||
return Object.values(data.artists).filter(a => ids.includes(String(a.id))) | ||
} | ||
} | ||
} | ||
|
||
const entities = { | ||
Artist: { | ||
referenceListResolverName: 'artists', | ||
keys: [{ field: 'id' }] | ||
} | ||
} | ||
|
||
module.exports = { name: 'artists', schema, reset, resolvers, entities, data } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
'use strict' | ||
|
||
const schema = ` | ||
type Movie { | ||
id: ID! | ||
title: String | ||
directorId: ID | ||
} | ||
type Query { | ||
movies(ids: [ID!]!): [Movie] | ||
} | ||
type Artist { | ||
id: ID | ||
movies: [Movie] | ||
} | ||
extend type Movie { | ||
director: Artist | ||
} | ||
extend type Query { | ||
movieArtists (ids: [ID!]!): [Artist] | ||
} | ||
` | ||
|
||
const data = { | ||
movies: null | ||
} | ||
|
||
function reset () { | ||
data.movies = { | ||
10: { | ||
id: 10, | ||
title: 'Interstellar', | ||
directorId: 101 | ||
}, | ||
11: { | ||
id: 11, | ||
title: 'Oppenheimer', | ||
directorId: 101 | ||
}, | ||
12: { | ||
id: 12, | ||
title: 'La vita é bella', | ||
directorId: 102 | ||
} | ||
} | ||
} | ||
|
||
reset() | ||
|
||
const resolvers = { | ||
Query: { | ||
movies (_, { ids }) { | ||
return Object.values(data.movies).filter(a => ids.includes(String(a.id))) | ||
}, | ||
movieArtists: async (parent, args, context, info) => { | ||
return args.ids.map(id => ({ id })) | ||
} | ||
}, | ||
Movie: { | ||
director: (parent, args, context, info) => { | ||
return parent?.directorId ? { id: parent.directorId } : null | ||
} | ||
}, | ||
Artist: { | ||
// TODO dataloader here | ||
movies: (parent, args, context, info) => { | ||
return Object.values(data.songs).filter(a => String(a.directorId) === String(parent.id)) | ||
} | ||
} | ||
} | ||
|
||
const entities = { | ||
Movie: { | ||
referenceListResolverName: 'movies', | ||
keys: [{ field: 'id' }, { field: 'directorId', type: 'Artist' }] | ||
}, | ||
Artist: { | ||
referenceListResolverName: 'movieArtists', | ||
argsAdapter: (partialResults) => { | ||
return { ids: partialResults.map(r => r.id) } | ||
}, | ||
keys: [{ field: 'id' }] | ||
} | ||
} | ||
|
||
module.exports = { name: 'movies', schema, reset, resolvers, entities, data } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
'use strict' | ||
|
||
const schema = ` | ||
type Song { | ||
id: ID! | ||
title: String | ||
singerId: ID | ||
} | ||
type Query { | ||
songs(ids: [ID!]!): [Song] | ||
} | ||
type Artist { | ||
id: ID | ||
songs: [Song] | ||
} | ||
extend type Song { | ||
singer: Artist | ||
} | ||
extend type Query { | ||
songArtists (ids: [ID!]!): [Artist] | ||
} | ||
` | ||
|
||
const data = { | ||
songs: null | ||
} | ||
|
||
function reset () { | ||
data.songs = { | ||
1: { | ||
id: 1, | ||
title: 'Every you every me', | ||
singerId: 103 | ||
}, | ||
2: { | ||
id: 2, | ||
title: 'The bitter end', | ||
singerId: 103 | ||
}, | ||
3: { | ||
id: 3, | ||
title: 'Vieni via con me', | ||
singerId: 102 | ||
} | ||
} | ||
} | ||
|
||
reset() | ||
|
||
const resolvers = { | ||
Query: { | ||
async songs (_, { ids }) { | ||
return Object.values(data.songs).filter(a => ids.includes(String(a.id))) | ||
}, | ||
songArtists: async (parent, args, context, info) => { | ||
return args.ids.map(id => ({ id })) | ||
} | ||
}, | ||
Song: { | ||
singer: (parent, args, context, info) => { | ||
return parent?.singerId ? { id: parent.singerId } : null | ||
} | ||
}, | ||
Artist: { | ||
// TODO dataloader here | ||
songs: (parent, args, context, info) => { | ||
return Object.values(data.songs).filter(a => String(a.singerId) === String(parent.id)) | ||
} | ||
} | ||
} | ||
|
||
const entities = { | ||
Song: { | ||
referenceListResolverName: 'songs', | ||
keys: [{ field: 'id' }, { field: 'singerId', type: 'Artist' }] | ||
}, | ||
Artist: { | ||
referenceListResolverName: 'songArtists', | ||
argsAdapter: (partialResults) => { | ||
return { ids: partialResults.map(r => r.id) } | ||
}, | ||
keys: [{ field: 'id' }] | ||
} | ||
} | ||
|
||
module.exports = { name: 'songs', schema, reset, resolvers, entities, data } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.