diff --git a/.gitignore b/.gitignore index 1ac43d6..96378d9 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ node_modules/ # Intellij Configuration Files .idea/ -generated-schema.graphql \ No newline at end of file +# Always regenerate new types before running project +src/types.ts \ No newline at end of file diff --git a/codegen.ts b/codegen.ts index 2d893ed..d36beb0 100644 --- a/codegen.ts +++ b/codegen.ts @@ -17,4 +17,4 @@ const config: CodegenConfig = { }, }; -export default config; \ No newline at end of file +export default config; diff --git a/package-lock.json b/package-lock.json index fb20910..fcb4cdf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2996,44 +2996,6 @@ "@parcel/watcher-win32-x64": "2.4.0" } }, - "node_modules/@parcel/watcher-android-arm64": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@parcel/watcher-android-arm64/-/watcher-android-arm64-2.4.0.tgz", - "integrity": "sha512-+fPtO/GsbYX1LJnCYCaDVT3EOBjvSFdQN9Mrzh9zWAOOfvidPWyScTrHIZHHfJBvlHzNA0Gy0U3NXFA/M7PHUA==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-darwin-arm64": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@parcel/watcher-darwin-arm64/-/watcher-darwin-arm64-2.4.0.tgz", - "integrity": "sha512-T/At5pansFuQ8VJLRx0C6C87cgfqIYhW2N/kBfLCUvDhCah0EnLLwaD/6MW3ux+rpgkpQAnMELOCTKlbwncwiA==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, "node_modules/@parcel/watcher-darwin-x64": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/@parcel/watcher-darwin-x64/-/watcher-darwin-x64-2.4.0.tgz", @@ -3053,177 +3015,6 @@ "url": "https://opencollective.com/parcel" } }, - "node_modules/@parcel/watcher-freebsd-x64": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@parcel/watcher-freebsd-x64/-/watcher-freebsd-x64-2.4.0.tgz", - "integrity": "sha512-dHTRMIplPDT1M0+BkXjtMN+qLtqq24sLDUhmU+UxxLP2TEY2k8GIoqIJiVrGWGomdWsy5IO27aDV1vWyQ6gfHA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-linux-arm-glibc": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm-glibc/-/watcher-linux-arm-glibc-2.4.0.tgz", - "integrity": "sha512-9NQXD+qk46RwATNC3/UB7HWurscY18CnAPMTFcI9Y8CTbtm63/eex1SNt+BHFinEQuLBjaZwR2Lp+n7pmEJPpQ==", - "cpu": [ - "arm" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-linux-arm64-glibc": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm64-glibc/-/watcher-linux-arm64-glibc-2.4.0.tgz", - "integrity": "sha512-QuJTAQdsd7PFW9jNGaV9Pw+ZMWV9wKThEzzlY3Lhnnwy7iW23qtQFPql8iEaSFMCVI5StNNmONUopk+MFKpiKg==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-linux-arm64-musl": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm64-musl/-/watcher-linux-arm64-musl-2.4.0.tgz", - "integrity": "sha512-oyN+uA9xcTDo/45bwsd6TFHa7Lc7hKujyMlvwrCLvSckvWogndCEoVYFNfZ6JJ2KNL/6fFiGPcbjp8jJmEh5Ng==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-linux-x64-glibc": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-x64-glibc/-/watcher-linux-x64-glibc-2.4.0.tgz", - "integrity": "sha512-KphV8awJmxU3q52JQvJot0QMu07CIyEjV+2Tb2ZtbucEgqyRcxOBDMsqp1JNq5nuDXtcCC0uHQICeiEz38dPBQ==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-linux-x64-musl": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-x64-musl/-/watcher-linux-x64-musl-2.4.0.tgz", - "integrity": "sha512-7jzcOonpXNWcSijPpKD5IbC6xC7yTibjJw9jviVzZostYLGxbz8LDJLUnLzLzhASPlPGgpeKLtFUMjAAzM+gSA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-win32-arm64": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@parcel/watcher-win32-arm64/-/watcher-win32-arm64-2.4.0.tgz", - "integrity": "sha512-NOej2lqlq8bQNYhUMnOD0nwvNql8ToQF+1Zhi9ULZoG+XTtJ9hNnCFfyICxoZLXor4bBPTOnzs/aVVoefYnjIg==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-win32-ia32": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@parcel/watcher-win32-ia32/-/watcher-win32-ia32-2.4.0.tgz", - "integrity": "sha512-IO/nM+K2YD/iwjWAfHFMBPz4Zqn6qBDqZxY4j2n9s+4+OuTSRM/y/irksnuqcspom5DjkSeF9d0YbO+qpys+JA==", - "cpu": [ - "ia32" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-win32-x64": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@parcel/watcher-win32-x64/-/watcher-win32-x64-2.4.0.tgz", - "integrity": "sha512-pAUyUVjfFjWaf/pShmJpJmNxZhbMvJASUpdes9jL6bTEJ+gDxPRSpXTIemNyNsb9AtbiGXs9XduP1reThmd+dA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, "node_modules/@peculiar/asn1-schema": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/@peculiar/asn1-schema/-/asn1-schema-2.3.8.tgz", diff --git a/src/context.ts b/src/context.ts index cb52346..36fb2a2 100644 --- a/src/context.ts +++ b/src/context.ts @@ -4,4 +4,4 @@ export type DataSourceContext = { dataSources: { spotifyAPI: SpotifyAPI; }; -}; \ No newline at end of file +}; diff --git a/src/datasources/spotify-client.ts b/src/datasources/spotify-client.ts new file mode 100644 index 0000000..e49f403 --- /dev/null +++ b/src/datasources/spotify-client.ts @@ -0,0 +1,24 @@ +import { RESTDataSource } from "@apollo/datasource-rest"; + +export class SpotifyAPI extends RESTDataSource { + baseURL = "https://spotify-demo-api-fe224840a08c.herokuapp.com/v1/"; + + async getFeaturedPlaylists() { + const { playlists = [] } = await this.get("browse/featured-playlists"); + const { items = [] } = playlists; + return items; + } + + addItemsToPlaylist(input: { playlistId: string; uris: string[] }) { + const { playlistId, uris } = input; + return this.post(`playlists/${playlistId}/tracks`, { + params: { + uris: uris.join(","), + }, + }); + } + + getPlaylist(playlistId: string) { + return this.get(`playlists/${playlistId}`); + } +} diff --git a/src/index.ts b/src/index.ts index 977f61b..2a7adb9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,4 +24,4 @@ async function startApolloServer() { `); } -startApolloServer(); \ No newline at end of file +startApolloServer(); diff --git a/src/models.ts b/src/models.ts index 998714a..50ad85c 100644 --- a/src/models.ts +++ b/src/models.ts @@ -30,4 +30,4 @@ export type AddItemsToPlaylistPayloadModel = { success: boolean; message: string; playlistId: string; -} \ No newline at end of file +} diff --git a/src/resolvers.ts b/src/resolvers.ts index 372cde0..ebe6815 100644 --- a/src/resolvers.ts +++ b/src/resolvers.ts @@ -50,4 +50,4 @@ export const resolvers: Resolvers = { return durationMs; } } -} \ No newline at end of file +} diff --git a/src/schema.ts b/src/schema.ts index 12d5681..8c57997 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -53,4 +53,4 @@ export const typeDefs = gql` "The URI for the track, usually a Spotify link." uri: String! } -`; \ No newline at end of file +`;