GraphQLByName is similar to the GraphQL function except that queries saved in the queries folder can directly be used just by their name (filename).
(c context.Context, name string, vars json.RawMessage, rc *RequestConfig, )
| 786 | // GraphQLByName is similar to the GraphQL function except that queries saved |
| 787 | // in the queries folder can directly be used just by their name (filename). |
| 788 | func (g *GraphJin) GraphQLByName(c context.Context, |
| 789 | name string, |
| 790 | vars json.RawMessage, |
| 791 | rc *RequestConfig, |
| 792 | ) (res *Result, err error) { |
| 793 | gj, err := g.getEngine() |
| 794 | if err != nil { |
| 795 | return |
| 796 | } |
| 797 | |
| 798 | c1, span := gj.spanStart(c, "GraphJin Query") |
| 799 | defer span.End() |
| 800 | |
| 801 | item, err := gj.allowList.GetByName(name, gj.prod) |
| 802 | if err != nil { |
| 803 | err = fmt.Errorf("%w: %s", err, name) |
| 804 | return |
| 805 | } |
| 806 | |
| 807 | r := gj.newGraphqlReq(rc, "", name, nil, vars) |
| 808 | r.Set(item) |
| 809 | |
| 810 | res, err = gj.queryWithResult(c1, r) |
| 811 | return |
| 812 | } |
| 813 | |
| 814 | // GraphQLByNameTx is similiar to the GraphQLByName function except |
| 815 | // that it can be used within a database transactions. |