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
Query: { | |
movie: async (_source, { id }, { dataSources }) => { | |
return dataSources.moviesAPI.getMovie(id); | |
}, | |
mostViewedMovies: async (_source, _args, { dataSources }) => { | |
return dataSources.moviesAPI.getMostViewedMovies(); | |
}, | |
favorites: async (_source, _args, { dataSources }) => { | |
return dataSources.personalizationAPI.getFavorites(); | |
}, |
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 server = new ApolloServer({ | |
typeDefs, | |
resolvers, | |
dataSources: () => { | |
return { | |
moviesAPI: new MoviesAPI(), | |
personalizationAPI: new PersonalizationAPI(), | |
}; | |
}, | |
context: () => { |
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 class PersonalizationAPI extends RESTDataSource { | |
baseURL = 'https://personalization-api.example.com'; | |
willSendRequest(request: Request) { | |
request.headers.set('Authorization', this.context.token); | |
} | |
private progressLoader = new DataLoader(async (ids: string[]) => { | |
const progressList = await this.get('progress', { | |
ids: ids.join(','), |
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
{ | |
series(id: "98794") { | |
title | |
description | |
season(number: 1) { | |
episodes { | |
id | |
episodeNumber | |
assetTitle | |
description |
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
class PersonalizationAPI extends RESTDataSource { | |
baseURL = 'https://personalization-api.example.com'; | |
willSendRequest(request: Request) { | |
request.headers.set('Authorization', this.context.token); | |
} | |
async getFavorites() { | |
return this.get('favorites'); | |
} |
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
class MoviesAPI extends RESTDataSource { | |
baseURL = 'https://movies-api.example.com'; | |
async getMovie(id: string) { | |
return this.get(`movies/${id}`); | |
} | |
async getMostViewedMovies(limit: number = 10) { | |
const data = await this.get('movies', { | |
per_page: limit, |
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
{ | |
"data": { | |
"hero": { | |
"name": "Luke Skywalker", | |
"friends": [ | |
{ | |
"name": "Han Solo" | |
}, | |
{ | |
"name": "Leia Organa" |
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
typealias Raw = [String: JSONDecodable & JSONEncodable] | |
extension Dictionary: JSONDecodable { | |
public init(jsonValue value: JSONValue) throws { | |
guard let dictionary = forceBridgeFromObjectiveC(value) as? Dictionary else { | |
throw JSONDecodingError.couldNotConvert(value: value, to: Dictionary.self) | |
} | |
self = dictionary | |
} | |
} |
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": { | |
"types": [ | |
{ | |
"kind": "UNION", | |
"name": "ContentNode", | |
"possibleTypes": [ | |
{ | |
"name": "Element" | |
}, | |
{ |
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
mkdir -p ${TARGET_BUILD_DIR}/${WRAPPER_NAME}/Resources/BridgeSupport | |
gen_bridge_metadata --64-bit -f ${TARGET_BUILD_DIR}/${WRAPPER_NAME} -o ${TARGET_BUILD_DIR}/${WRAPPER_NAME}/Resources/BridgeSupport/${TARGET_NAME}.bridgesupport |