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 (r *queryResolver) ChatRoom(ctx context.Context, id string) (*model.ChatRoom, error) { | |
| if t, ok := r.ChatRooms[id]; ok { | |
| return &t, nil | |
| } | |
| return nil, errors.New("chat room not found") | |
| } |
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
| srv := handler.NewDefaultServer(generated.NewExecutableSchema(graph.NewResolver())) |
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 (r *chatRoomResolver) MessagesConnection(ctx context.Context, | |
| obj *model.ChatRoom, first *int, after *string) (*model.MessagesConnection, error) { | |
| panic(fmt.Errorf("not implemented")) | |
| } | |
| func (r *queryResolver) ChatRoom(ctx context.Context, id string) (*model.ChatRoom, error) { | |
| panic(fmt.Errorf("not implemented")) | |
| } |
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 model | |
| type ChatRoom struct { | |
| ID string | |
| Name 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
| package model | |
| type ChatRoom struct { | |
| ID string `json:"id"` | |
| MessagesConnection *MessagesConnection `json:"messagesConnection"` | |
| } | |
| type Message struct { | |
| ID string `json:"id"` | |
| Text *string `json:"text"` |
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 Message { | |
| id: ID! | |
| text: String | |
| } | |
| type ChatRoom { | |
| id: ID! | |
| name: String | |
| messagesConnection: # this is what we're going to implement | |
| } |
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 { relayStylePagination } from '@apollo/client/utilities' | |
| const client = new ApolloClient({ | |
| uri: 'http://localhost:4000/query', | |
| cache: new InMemoryCache({ | |
| typePolicies: { | |
| ChatRoom: { | |
| fields: { | |
| messagesConnection: relayStylePagination(), | |
| }, |
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
| query { | |
| chatRoom(id: 1) { | |
| id | |
| name | |
| messagesConnection(first: 10) { | |
| edges { | |
| node { | |
| id | |
| text | |
| } |
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 (r *chatRoomResolver) MessagesConnection(ctx context.Context, obj *model.ChatRoom, | |
| first *int, after *string) (*model.MessagesConnection, error) { | |
| // The cursor is base64 encoded by convention, so we need to decode it first | |
| var decodedCursor string | |
| if after != nil { | |
| b, err := base64.StdEncoding.DecodeString(*after) | |
| if err != nil { | |
| return nil, 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
| package graph | |
| import ( | |
| "fmt" | |
| "math/rand" | |
| "strconv" | |
| "time" | |
| "github.com/kabece/gqlgen-chatroom/graph/generated" | |
| "github.com/kabece/gqlgen-chatroom/graph/model" |
NewerOlder