chat

package module
v0.0.0-...-78a4a23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 22 Imported by: 0

README

Chat Demo

Getting started

  1. Install go modules & npm dependencies
go mod download
npm i
  1. Start server and start react client
chmod +x start-server.sh
./start-server.sh
npm run start

Example is forked from: gqlgen

Example(s)

mutation SendMessage {
  post(roomName: "#test", username: "me", text: "hello!") {
    ...MessageData
  }
}

query GetMessages {
  room(name:"#test") {
    name
    messages {
      ...MessageData
    }
  }
}

subscription LiveMessages {
  messageAdded(roomName: "#test") {
    ...MessageData
  }
}

fragment MessageData on Message{
  id
  text
  createdBy
  createdAt
}

Documentation

Index

Constants

View Source
const (
	MutationSendMessage = `mutation SendMessage{
	post(roomName: "#test", username: "myuser", text: "Hello World!") {
		text
		createdBy
	}
}`

	QueryGetMessages = `query GetMessages {
	room(name:"#test") {
		name
		messages {
			text
			createdBy
		}
	}
}`

	SubscriptionLiveMessages = `subscription LiveMessages {
	messageAdded(roomName: "#test") {
		text
		createdBy
	}
}`

	InvalidSubscriptionLiveMessages = `` /* 130-byte string literal not displayed */

	InvalidOperation = `query InvalidOperation {
	serverName
}
`
)

Variables

This section is empty.

Functions

func GraphQLEndpointHandler

func GraphQLEndpointHandler() http.Handler

func GraphQLRequestForOperation

func GraphQLRequestForOperation(operation string) ([]byte, error)

func LoadSchemaFromExamplesDirectoryWithinPkg

func LoadSchemaFromExamplesDirectoryWithinPkg() ([]byte, error)

func NewExecutableSchema

func NewExecutableSchema(cfg Config) graphql.ExecutableSchema

NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface.

Types

type Chatroom

type Chatroom struct {
	Name      string
	Messages  []Message
	Observers map[string]struct {
		Username string
		Message  chan *Message
	}
}

type ComplexityRoot

type ComplexityRoot struct {
	Chatroom struct {
		Messages func(childComplexity int) int
		Name     func(childComplexity int) int
	}

	Message struct {
		CreatedAt func(childComplexity int) int
		CreatedBy func(childComplexity int) int
		ID        func(childComplexity int) int
		Text      func(childComplexity int) int
	}

	Mutation struct {
		Post func(childComplexity int, text string, username string, roomName string) int
	}

	Query struct {
		Room func(childComplexity int, name string) int
	}

	Subscription struct {
		MessageAdded func(childComplexity int, roomName string) int
	}
}

type Config

type Config struct {
	Resolvers  ResolverRoot
	Directives DirectiveRoot
	Complexity ComplexityRoot
}

func New

func New() Config

type DirectiveRoot

type DirectiveRoot struct {
	User func(ctx context.Context, obj interface{}, next graphql.Resolver, username string) (res interface{}, err error)
}

type Message

type Message struct {
	ID        string    `json:"id"`
	Text      string    `json:"text"`
	CreatedBy string    `json:"createdBy"`
	CreatedAt time.Time `json:"createdAt"`
}

type MutationResolver

type MutationResolver interface {
	Post(ctx context.Context, text string, username string, roomName string) (*Message, error)
}

type QueryResolver

type QueryResolver interface {
	Room(ctx context.Context, name string) (*Chatroom, error)
}

type ResolverRoot

type ResolverRoot interface {
	Mutation() MutationResolver
	Query() QueryResolver
	Subscription() SubscriptionResolver
	// contains filtered or unexported methods
}

type SubscriptionResolver

type SubscriptionResolver interface {
	MessageAdded(ctx context.Context, roomName string) (<-chan *Message, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL