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 { Tracks, Albums, Artists } from '../../db'; | |
| import { tracksQuery } from '../utils'; | |
| export const track = (_, { id }) => Tracks.findById(id); | |
| export const tracks = (_, args) => Tracks.find(...tracksQuery(args)); | |
| export const album = (_, { id }) => Albums.findById(id); | |
| export const albums = (_, { limit }) => Albums.find({}, {}, { limit, sort: { rating: 1 } }); |
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 mongoose, { Schema } from 'mongoose'; | |
| export const artistSchema = Schema({ | |
| name: String, | |
| rating: Number, | |
| startActivity: Date, | |
| endActivity: Date, | |
| country: String, | |
| photo: String, | |
| website: 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
| type Query { | |
| track(id: ID!): Track | |
| tracks( | |
| limit: Int = 20 | |
| sortBy: TrackSortable = RATING | |
| genres: [Genre], | |
| artists: [ID!] | |
| countries: [String!] | |
| ): [Track] | |
| album(id: ID!): Album |
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
| interface ArtistType { | |
| type: ArtistTypesEnum! | |
| } | |
| type Single implements ArtistType { | |
| type: ArtistTypesEnum! | |
| birthDate: Date | |
| instruments: [MusicianInstrument] | |
| } |
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 express from 'express'; | |
| import bodyParser from 'body-parser'; | |
| import cors from 'cors'; | |
| import { graphqlExpress, graphiqlExpress } from 'apollo-server-express'; | |
| import { makeExecutableSchema } from 'graphql-tools'; | |
| import root from './type-defs/root.graphql'; | |
| const app = express(); | |
| const schema = makeExecutableSchema({ |
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
| type Track { | |
| _id: ID! # Unique identifier | |
| name: String! | |
| rating: Float! | |
| genres: [Genre]! # List of allowed genres | |
| releasedAt: Date! # Date is a custom Scalar | |
| label: String | |
| logo: URL # URL is a custom Scalar too | |
| url: URL! | |
| artists: [Artist!]! # Non-nullable list of non-nullable Artists |
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
| schema { | |
| query: Query | |
| } | |
| type Query { | |
| hello: 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
| // send invitation to new user | |
| sendNotification(NotificationTypes.invitation, 'some_user_id', { | |
| // some custom data to render at notification's text | |
| invitationLink: 'https://myservice.com/invitation/accept/abcdefg1234', | |
| expirationDate: moment().subtract(5, 'day').format('YYYY-MM-DD'), | |
| }); |
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
| export function sendNotification(notificationType, userId, context) { | |
| const _locale = getLocaleByUserId(userId); | |
| NotificationTypes[notificationType].forEach((sendMethod) => { | |
| // localize notification message for particular locale | |
| const text = i18n.__(`notifications.${notificationType}.${sendMethod}`, { _locale, ...context }); | |
| // send message | |
| sendersMap[sendMethod](userId, text); | |
| }); |