This file contains hidden or 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
| const flatten = (arr) => { | |
| return Array.isArray(arr) ? [].concat(...arr.map(flatten)) : arr; | |
| } | |
| let ar = [[1,2,3], [4, [5, 6]], [[7, [8, [9]]]]]; // [1, 2, 3, 4, 5, 6, 7, 8, 9] |
This file contains hidden or 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
| import { RequestOptions, RESTDataSource } from "apollo-datasource-rest"; | |
| import { ApolloError, AuthenticationError } from "apollo-server"; | |
| // Local Types | |
| export type IResourceTypes = "album" | "artist" | "track" | "user"; | |
| export type IMethodTypes = | |
| | "getInfo" | |
| | "getTags" | |
| | "search" | |
| | "getSimilar" |
This file contains hidden or 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
| import { IResolvers } from "graphql-tools"; | |
| const UserResolvers: IResolvers = { | |
| User: { | |
| info: async ({ user }, _args, { dataSources: { LastFM } }) => { | |
| const data = await LastFM.call({ resource: "user", method: "getInfo", user }); | |
| return data.user; | |
| }, | |
| charts: ({ user }) => ({ user }), | |
| tracks: ({ user }, { limit, page }) => ({ user, limit, page }), |
This file contains hidden or 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
| import { UserInputError } from "apollo-server"; | |
| import { IResolvers } from "graphql-tools"; | |
| import merge from "lodash.merge"; | |
| // LastFM Resource Resolvers | |
| import { AlbumsResolvers } from "./album"; | |
| import { ArtistResolver } from "./artist"; | |
| import { TrackResolver } from "./track"; | |
| import { UserResolvers } from "./user"; |
This file contains hidden or 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
| import { IResolvers } from "graphql-tools"; | |
| import merge from "lodash.merge"; | |
| import { LastFMResolvers } from "./lastfm"; | |
| import { SharedResolvers } from "./shared"; | |
| const RootQueryResolver: IResolvers = { | |
| Query: { | |
| lastfm: () => ({}) | |
| } |
This file contains hidden or 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
| import { gql } from "apollo-server"; | |
| import { DocumentNode } from "graphql"; | |
| const UserDefs: DocumentNode = gql` | |
| extend type LastFM { | |
| users( | |
| "The user to fetch info for." | |
| user: String! | |
| ): User | |
| } |
This file contains hidden or 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
| import { gql } from "apollo-server"; | |
| import { DocumentNode } from "graphql"; | |
| // Type Defs | |
| import { AlbumDefs } from "./album"; | |
| import { ArtistDefs } from "./artist"; | |
| import { TagDefs } from "./tag"; | |
| import { TrackDefs } from "./track"; | |
| import { UserDefs } from "./user"; |
This file contains hidden or 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
| import { gql } from "apollo-server"; | |
| import { DocumentNode } from "graphql"; | |
| // Our Shared Type Definitions | |
| const SharedDefs: DocumentNode = gql` | |
| "Last.fm image resource" | |
| type Image { | |
| size: String! | |
| url: String! | |
| } |
This file contains hidden or 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
| import { gql } from "apollo-server"; | |
| import { DocumentNode } from "graphql"; | |
| // TypeDefs | |
| import { LastFMSchemaDefs } from "./lastfm"; | |
| import { SharedSchemaDefs } from "./shared"; | |
| const RootDefs: DocumentNode = gql` | |
| type Query { | |
| _empty: String |
This file contains hidden or 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
| import { ApolloServer } from "apollo-server"; | |
| import * as dotenv from "dotenv"; | |
| // Process env | |
| dotenv.config(); | |
| // Apollo-Server Schema | |
| import { schema } from "./schema"; | |
| // GraphQL Server |