Skip to content

Instantly share code, notes, and snippets.

View daniele-zurico's full-sized avatar

Daniele Zurico daniele-zurico

View GitHub Profile
import { postController } from "../controllers/controllers";
const postResolver = {
Query: {
posts(root: any, args: any, context: any) {
return postController.posts();
}
},
Mutation: {
addPost(root: any, args: any, context: any) {
import { Post } from "../models/posts";
const postController = {
posts: () => Post.find({}),
addPost: (post: any) => {
const newPost = new Post({author: post.author, comment: post.comment});
return newPost.save();
}
};
import {
addMockFunctionsToSchema,
gql,
makeExecutableSchema
} from "apollo-server";
import { GraphQLSchema } from "graphql";
const postSchema: GraphQLSchema = makeExecutableSchema({
typeDefs: gql`
type Query {
import { postController } from "../controllers/controllers";
import { pubsub } from "../server";
const POST_ADDED = 'POST_ADDED';
const postResolver = {
Subscription: {
postAdded: {
subscribe: () => pubsub.asyncIterator([POST_ADDED])
}
export const pubsub = new PubSub();
const MONGO_PORT = 27017;
const MONGO_URL = "localhost";
const dbName = "graphExample";
export const CLIENT_ID =
"YOUR_ID";
export const client = new OAuth2Client(CLIENT_ID);
// help to debug mongoose
mongoose.set("debug", true);
import {
addMockFunctionsToSchema,
gql,
makeExecutableSchema
} from "apollo-server";
import { GraphQLSchema } from "graphql";
const postSchema: GraphQLSchema = makeExecutableSchema({
typeDefs: gql`
type Query {
import { postController } from "../controllers/controllers";
const postResolver = {
Query: {
posts(root: any, args: any, context: any) {
return postController.posts();
}
},
Mutation: {
addPost(root: any, args: any, context: any) {
imports: [
...
MatCardModule,
MatButtonModule,
MatIconModule,
MatProgressSpinnerModule,
],
...
providers: [SwapiService],
exports: [HeroListComponent],
export interface Hero {
url: string;
name: string;
birth_year: string;
eye_color: string;
gender: string;
homeworld: string;
hair_color: string;
height: number;
films: string[];
<mat-card>
<mat-card-header>
<mat-card-title><strong>{{ hero.name }}</strong></mat-card-title>
</mat-card-header>
<mat-card-content>
<p>
Birth Date: <strong>{{ hero.birth_year }}</strong>
</p>
<p>
Eyes: <mat-icon [ngClass]="hero.eye_color">remove_red_eye</mat-icon>