Skip to content

Instantly share code, notes, and snippets.

View martijnwalraven's full-sized avatar

Martijn Walraven martijnwalraven

View GitHub Profile
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();
},
const server = new ApolloServer({
typeDefs,
resolvers,
dataSources: () => {
return {
moviesAPI: new MoviesAPI(),
personalizationAPI: new PersonalizationAPI(),
};
},
context: () => {
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(','),
{
series(id: "98794") {
title
description
season(number: 1) {
episodes {
id
episodeNumber
assetTitle
description
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');
}
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,
{
"data": {
"hero": {
"name": "Luke Skywalker",
"friends": [
{
"name": "Han Solo"
},
{
"name": "Leia Organa"
@martijnwalraven
martijnwalraven / Raw.swift
Created October 13, 2017 05:41
Hacky way of getting a custom GraphQL scalar for raw JSON to work in Apollo iOS
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
}
}
"__schema": {
"types": [
{
"kind": "UNION",
"name": "ContentNode",
"possibleTypes": [
{
"name": "Element"
},
{
@martijnwalraven
martijnwalraven / gist:700216
Created November 15, 2010 09:46
Script to generate BridgeSupport file for a framework from Xcode
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