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
const FirstQuery = gql` | |
query One { | |
one | |
} | |
`; | |
const SecondQuery = gql` | |
query Two { | |
two | |
} |
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
const FirstQuery = gql` | |
query One { | |
one | |
} | |
`; | |
const SecondQuery = gql` | |
query Two { | |
two | |
} |
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
dcs |
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
import { ApolloServer, gql } from 'apollo-server'; | |
import mapKeys from 'lodash/mapKeys'; | |
import { MvrpAPI } from './datasource'; | |
const typeDefs = gql` | |
type Car { | |
id: Int! | |
plateNumber: String! | |
color: String! | |
model: String! |
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
const resolvers = { | |
Query: { | |
car: (root, { plateNumber }, { dataSources }) => dataSources.mvrpAPI.getACar(plateNumber), | |
cars: (root, args, { dataSources }) => dataSources.mvrpAPI.getAllCars(), | |
}, | |
Car: { | |
vehicleStatus: ({ status }) => status, | |
yearOfManufacture: ({ productionYear }) => productionYear, | |
}, | |
}; |
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
import { ApolloServer, gql } from 'apollo-server'; | |
import { MvrpAPI } from './datasource'; | |
... | |
... | |
const server = new ApolloServer({ | |
typeDefs, | |
resolvers, |
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
import { RESTDataSource } from 'apollo-datasource-rest'; | |
export class MvrpAPI extends RESTDataSource { | |
constructor() { | |
super(); | |
this.baseURL = 'https://mvrp.herokuapp.com/api/'; | |
} | |
async getAllCars() { | |
return this.get('cars'); |
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
import { ApolloServer, gql } from 'apollo-server'; | |
const typeDefs = gql` | |
type Car { | |
id: Int! | |
plateNumber: String! | |
color: String! | |
model: String! | |
chasisNumber: String! | |
vehicleStatus: String! |
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
const GET_DOG_PHOTO = gql` | |
query dog($breed: String!) { | |
dog(breed: $breed) { | |
id | |
displayImage | |
} | |
}`; | |
export const queryComponent = `const DogPhoto = ({ breed }) => ( |
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
const { RESTDataSource } = require('apollo-datasource-rest'); | |
class MoviesAPI extends RESTDataSource { | |
constructor() { | |
super(); | |
this.baseURL = 'https://movies-api.example.com/'; | |
} | |
async getMovie(id) { | |
return this.get(`movies/${id}`); |