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
| package main | |
| // Note how the main package is the only one importing | |
| // other local packages. | |
| import ( | |
| "github.com/myproject/config" | |
| "github.com/myproject/database" | |
| "github.com/myproject/handler" | |
| "net/http" | |
| ) |
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
| package database | |
| type SomeUserDB struct{} | |
| func (db *SomeUserDB) UserRoleByID(id string) string { | |
| // implementation | |
| } |
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
| package database | |
| type SomeConfigDB struct{} | |
| func (db *SomeConfigDB) AllPermissions() map[string][]string { | |
| // implementation | |
| } |
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
| package config | |
| import ( | |
| "time" | |
| ) | |
| // Here we declare an interface representing our local | |
| // needs from the configuration db, namely, | |
| // the `AllPermissions` method. | |
| type PermissionDB interface { |
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
| package handler | |
| import ( | |
| "fmt" | |
| "net/http" | |
| "strings" | |
| ) | |
| // Declaring our local needs from the user db instance, | |
| type UserDB interface { |
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 typeDefs = gql` | |
| type Name { | |
| title: String, | |
| first: String, | |
| last: String, | |
| } | |
| type Location { | |
| street: String | |
| city: String | |
| state: 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
| const { RESTDataSource } = require("apollo-datasource-rest"); | |
| class RandomUser extends RESTDataSource { | |
| constructor() { | |
| super(); | |
| this.baseURL = "https://randomuser.me/api/"; | |
| } | |
| } | |
| module.exports = RandomUser; |
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
| async getThing(id) { | |
| return this.get(`things/${id}`); | |
| } |
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 { RESTDataSource } = require("apollo-datasource-rest"); | |
| class RandomUser extends RESTDataSource { | |
| constructor() { | |
| super(); | |
| this.baseURL = "https://randomuser.me/api"; | |
| } | |
| async getUser() { | |
| const user = await this.get("/"); |
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: () => ({ | |
| RandomUser: new RandomUser() | |
| }) | |
| }); |