Skip to content

Instantly share code, notes, and snippets.

View chris001177's full-sized avatar

Chris chris001177

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