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

Method executeGraphQLRoleQuery

core/role_query.go:73–131  ·  view source on GitHub ↗
(
	c context.Context,
	conn *sql.Conn,
	vmap map[string]json.RawMessage,
	rc *RequestConfig,
)

Source from the content-addressed store, hash-verified

71}
72
73func (gj *graphjinEngine) executeGraphQLRoleQuery(
74 c context.Context,
75 conn *sql.Conn,
76 vmap map[string]json.RawMessage,
77 rc *RequestConfig,
78) (role string, err error) {
79 role = "user"
80
81 pdb := gj.primaryDB()
82 if pdb == nil || pdb.psqlCompiler == nil {
83 return "", fmt.Errorf("roles_query: primary database not initialized")
84 }
85 if gj.roleGraphQLStmt.qc == nil {
86 return "", fmt.Errorf("roles_query: graphql roles_query not initialized")
87 }
88
89 vars := roleQueryVars(vmap, gj.roleGraphQLStmt.qc.Vars)
90 ar, err := gj.argList(c,
91 gj.roleGraphQLStmt.md,
92 vars,
93 rc,
94 false,
95 pdb.psqlCompiler)
96 if err != nil {
97 return "", err
98 }
99
100 query, queryArgs, err := prepareQueryArgsForDB(pdb.dbtype, gj.roleGraphQLStmt.sql, ar.values)
101 if err != nil {
102 return "", err
103 }
104
105 raw, err := scanJSONRow(c, pdb.dbtype, conn, requestTx(rc), query, queryArgs)
106 if err == sql.ErrNoRows {
107 return role, nil
108 }
109 if err != nil {
110 return "", err
111 }
112
113 attrs, empty, err := extractRoleQueryAttrs(raw)
114 if err != nil {
115 return "", err
116 }
117 if empty {
118 return role, nil
119 }
120
121 for _, rm := range gj.roleGraphQLMatches {
122 ok, err := rm.expr.eval(attrs)
123 if err != nil {
124 return "", fmt.Errorf("roles_query: role %q match failed: %w", rm.role, err)
125 }
126 if ok {
127 return rm.role, nil
128 }
129 }
130 return role, nil

Callers 1

executeRoleQueryMethod · 0.95

Calls 8

primaryDBMethod · 0.95
argListMethod · 0.95
roleQueryVarsFunction · 0.85
prepareQueryArgsForDBFunction · 0.85
scanJSONRowFunction · 0.85
requestTxFunction · 0.85
extractRoleQueryAttrsFunction · 0.85
evalMethod · 0.65

Tested by

no test coverage detected