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 | |
| import ( | |
| "bytes" | |
| "fmt" | |
| "io" | |
| "log" | |
| "mime/multipart" | |
| "net/http" | |
| "os" |
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
| //Retrieves movie detail based on id from SQLite. If not available makes a network call to retrieve movie details from API | |
| suspend fun getMovieDetails(movieId: Int): Flow<MovieDetails> { | |
| val movieDetailsCacheResponse:Flow<MovieDetailsEntity>? = appDatabase.movieDetailsDao().getPopularShows(movieId) | |
| return if (movieDetailsCacheResponse != null) { | |
| Timber.e("MovieDetailsDataSource: Fetching movie details from cache") | |
| return movieDetailsCacheResponse.map { it?.toDomain() } | |
| } else { | |
| Timber.e("MovieDetailsDataSource: Fetching movie details from network") |
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
| func main() { | |
| fmt.Println("Starting graphql server...") | |
| } |
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
| type Note struct { | |
| ID int `json: "id"` | |
| Title string `json: "title"` | |
| Description string `json: "description"` | |
| Created_At string `json: "created_at"` | |
| } | |
| /**Mock database*/ | |
| var notes = []Note{ | |
| {1, "Title 1", "Description 1", time.Now().UTC().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
| func main() { | |
| fmt.Println("Starting graphql server...") | |
| noteType := graphql.NewObject( | |
| graphql.ObjectConfig{ | |
| Name: "Note", | |
| Description: "User generated note", | |
| Fields: graphql.Fields{ | |
| "id": &graphql.Field{ | |
| Type: graphql.Int, |
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
| fields := graphql.Fields{ | |
| "notes": &graphql.Field{ | |
| Name: "Get all notes", | |
| Type: graphql.NewList(noteType), | |
| Description: "Get list of all notes", | |
| Resolve: func(params graphql.ResolveParams) (interface{}, error) { | |
| return notes, nil | |
| }, | |
| }, |
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
| rootQuery := graphql.ObjectConfig{ | |
| Name: "RootQuery", | |
| Fields: fields, | |
| } |
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
| schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)} | |
| schema, err := graphql.NewSchema(schemaConfig) | |
| if err != nil { | |
| log.Fatalf("Failed to create graphql schema: %v", err) | |
| } |
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
| handler := handler.New(&handler.Config{ | |
| Schema: &schema, | |
| Pretty: true, | |
| GraphiQL: false, | |
| }) | |
| http.Handle("/graphql", handler) |
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
| log.Fatal(http.ListenAndServe(":8080", nil)) |
OlderNewer