在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):graph-gophers/graphql-transport-ws开源软件地址(OpenSource Url):https://github.com/graph-gophers/graphql-transport-ws开源编程语言(OpenSource Language):Go 100.0%开源软件介绍(OpenSource Introduction):graphql-transport-ws(Work in progress!) A Go package that leverages WebSockets to transport GraphQL subscriptions, queries and mutations implementing the [email protected] protocol Use with graph-gophers/graphql-goTo use this library with github.com/graph-gophers/graphql-go you can wrap the package main
import (
"fmt"
"net/http"
graphql "github.com/graph-gophers/graphql-go"
"github.com/graph-gophers/graphql-go/relay"
"github.com/graph-gophers/graphql-transport-ws/graphqlws"
)
const schema = `
schema {
subscription: Subscription
}
type Subscription {
...
}
`
type resolver struct {
// ...
}
func main() {
// init graphQL schema
s, err := graphql.ParseSchema(schema, &resolver{})
if err != nil {
panic(err)
}
// graphQL handler
graphQLHandler := graphqlws.NewHandlerFunc(s, &relay.Handler{Schema: s})
http.HandleFunc("/graphql", graphQLHandler)
// start HTTP server
if err := http.ListenAndServe(fmt.Sprintf(":%d", 8080), nil); err != nil {
panic(err)
}
} For a more in depth example see this repo. ClientCheck apollographql/subscription-transport-ws for details on how to use WebSockets on the client side. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论