Skip to content

Instantly share code, notes, and snippets.

:octocat:
open sourcy and shit

Sara Vieira SaraVieira

:octocat:
open sourcy and shit
Block or report user

Report or block SaraVieira

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View users.graphql
{
getUsers(people: 3) {
name {
first
last
},
location {
city
}
}
View users.js
getUsers: async (_, { people }, { dataSources }) =>
dataSources.RandomUser.getUsers(people)
View users.js
async getUsers(people = 10) {
const user = await this.get(`/?results=${people}`);
return user.results;
}
View query.graphql
{
getUser {
name {
first
last
}
}
}
View resolvers.js
const resolvers = {
Query: {
getUser: async (_, __, { dataSources }) => dataSources.RandomUser.getUser()
}
};
View server.js
const server = new ApolloServer({
typeDefs,
resolvers,
dataSources: () => ({
RandomUser: new RandomUser()
})
});
View getUser.js
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("/");
View example.js
async getThing(id) {
return this.get(`things/${id}`);
}
View dataSource.js
const { RESTDataSource } = require("apollo-datasource-rest");
class RandomUser extends RESTDataSource {
constructor() {
super();
this.baseURL = "https://randomuser.me/api/";
}
}
module.exports = RandomUser;
View schema.js
const typeDefs = gql`
type Name {
title: String,
first: String,
last: String,
}
type Location {
street: String
city: String
You can’t perform that action at this time.