MCPcopy
hub / github.com/dosco/graphjin / Subscribe

Method Subscribe

core/subs.go:93–128  ·  view source on GitHub ↗

Subscribe function is called on the GraphJin struct to subscribe to query. Any database changes that apply to the query are streamed back in realtime. In developer mode all named queries are saved into the queries folder and in production mode only queries from these saved queries can be used.

(
	c context.Context,
	query string,
	vars json.RawMessage,
	rc *RequestConfig,
)

Source from the content-addressed store, hash-verified

91// In developer mode all named queries are saved into the queries folder and in production mode only
92// queries from these saved queries can be used.
93func (g *GraphJin) Subscribe(
94 c context.Context,
95 query string,
96 vars json.RawMessage,
97 rc *RequestConfig,
98) (m *Member, err error) {
99 // get the name, query vars
100 h, err := graph.FastParse(query)
101 if err != nil {
102 return
103 }
104
105 gj, err := g.getEngine()
106 if err != nil {
107 return
108 }
109
110 // create the request object
111 r := gj.newGraphqlReq(rc, "subscription", h.Name, nil, vars)
112
113 // if production security enabled then get query and metadata
114 // from allow list
115 if gj.prodSec {
116 var item allow.Item
117 item, err = gj.allowList.GetByName(h.Name, true)
118 if err != nil {
119 return
120 }
121 r.Set(item)
122 } else {
123 r.query = []byte(query)
124 }
125
126 m, err = gj.subscribe(c, r)
127 return
128}
129
130// SubscribeByName is similar to the Subscribe function except that queries saved
131// in the queries folder can directly be used by their filename.

Calls 5

getEngineMethod · 0.95
newGraphqlReqMethod · 0.80
GetByNameMethod · 0.80
subscribeMethod · 0.80
SetMethod · 0.65