GraphQL function is our main function it takes a GraphQL query compiles it
(c context.Context, r GraphqlReq)
| 884 | |
| 885 | // GraphQL function is our main function it takes a GraphQL query compiles it |
| 886 | func (gj *graphjinEngine) query(c context.Context, r GraphqlReq) ( |
| 887 | resp GraphqlResponse, err error, |
| 888 | ) { |
| 889 | resp.res = Result{ |
| 890 | namespace: r.namespace, |
| 891 | operation: r.operation, |
| 892 | name: r.name, |
| 893 | } |
| 894 | |
| 895 | if !gj.prodSec && r.name == "IntrospectionQuery" { |
| 896 | resp.res.Data, err = gj.getIntroResult() |
| 897 | return |
| 898 | } |
| 899 | |
| 900 | // Federation v2: intercept `_service { sdl }` and `_entities` queries |
| 901 | // before the normal compile pipeline. The compiler doesn't know about |
| 902 | // these fields and would reject them as unknown root selections. |
| 903 | if gj.conf.Federation.Enabled && r.operation == qcode.QTQuery { |
| 904 | handled, data, ferr := gj.handleFederationQuery(r) |
| 905 | if ferr != nil { |
| 906 | resp.res.Errors = newError(string(r.query), ferr) |
| 907 | err = ferr |
| 908 | return |
| 909 | } |
| 910 | if handled { |
| 911 | resp.res.Data = data |
| 912 | return |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | if r.operation == qcode.QTSubscription { |
| 917 | err = errors.New("use 'core.Subscribe' for subscriptions") |
| 918 | return |
| 919 | } |
| 920 | |
| 921 | if !gj.anyDatabaseReady() { |
| 922 | err = fmt.Errorf("no tables found in any database; schema not initialized") |
| 923 | return |
| 924 | } |
| 925 | |
| 926 | s, err := newGState(c, gj, r) |
| 927 | if err != nil { |
| 928 | return |
| 929 | } |
| 930 | err = s.compileAndExecuteWrapper(c) |
| 931 | |
| 932 | resp.qc = s.qcode() |
| 933 | resp.res.sql = s.sql() |
| 934 | resp.res.cacheControl = s.cacheHeader() |
| 935 | resp.res.Vars = r.vars |
| 936 | // Strip internal __gj_id fields unconditionally when cache tracking is enabled. |
| 937 | // This handles all code paths: cache hits, multi-DB queries, and regular queries. |
| 938 | if gj.conf.CacheTrackingEnabled { |
| 939 | s.data = stripGjIdFields(s.data) |
| 940 | } |
| 941 | resp.res.Data = json.RawMessage(s.data) |
| 942 | resp.res.Hash = s.dhash |
| 943 | resp.res.role = s.role |
no test coverage detected