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
| 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) { |
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
| 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(); | |
| } | |
| }; |
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
| import { | |
| addMockFunctionsToSchema, | |
| gql, | |
| makeExecutableSchema | |
| } from "apollo-server"; | |
| import { GraphQLSchema } from "graphql"; | |
| const postSchema: GraphQLSchema = makeExecutableSchema({ | |
| typeDefs: gql` | |
| type Query { |
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
| import { postController } from "../controllers/controllers"; | |
| import { pubsub } from "../server"; | |
| const POST_ADDED = 'POST_ADDED'; | |
| const postResolver = { | |
| Subscription: { | |
| postAdded: { | |
| subscribe: () => pubsub.asyncIterator([POST_ADDED]) | |
| } |
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
| 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); |
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
| import { | |
| addMockFunctionsToSchema, | |
| gql, | |
| makeExecutableSchema | |
| } from "apollo-server"; | |
| import { GraphQLSchema } from "graphql"; | |
| const postSchema: GraphQLSchema = makeExecutableSchema({ | |
| typeDefs: gql` | |
| type Query { |
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
| 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) { |
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
| imports: [ | |
| ... | |
| MatCardModule, | |
| MatButtonModule, | |
| MatIconModule, | |
| MatProgressSpinnerModule, | |
| ], | |
| ... | |
| providers: [SwapiService], | |
| exports: [HeroListComponent], |
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
| export interface Hero { | |
| url: string; | |
| name: string; | |
| birth_year: string; | |
| eye_color: string; | |
| gender: string; | |
| homeworld: string; | |
| hair_color: string; | |
| height: number; | |
| films: 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
| <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> |