Skip to content

Commit fe4ddab

Browse files
author
Alvaro Muñoz
committed
Add support for the gqlgen library
1 parent 656b4fc commit fe4ddab

File tree

487 files changed

+174523
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

487 files changed

+174523
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* Support for the gqlgen has been added.

go/ql/lib/go.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import semmle.go.frameworks.Encoding
4141
import semmle.go.frameworks.Gin
4242
import semmle.go.frameworks.Glog
4343
import semmle.go.frameworks.GoRestfulHttp
44+
import semmle.go.frameworks.Gqlgen
4445
import semmle.go.frameworks.K8sIoApimachineryPkgRuntime
4546
import semmle.go.frameworks.K8sIoApiCoreV1
4647
import semmle.go.frameworks.K8sIoClientGo
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/** Provides models of commonly used functions and types in the gqlgen packages. */
2+
3+
import go
4+
5+
/** Provides models of commonly used functions and types in the gqlgen packages. */
6+
module Gqlgen {
7+
class GqlgenGeneratedFile extends File {
8+
GqlgenGeneratedFile() {
9+
exists(DataFlow::CallNode call |
10+
call.getReceiver().getType().hasQualifiedName("github.com/99designs/gqlgen/graphql", _) and
11+
call.getFile() = this
12+
)
13+
}
14+
}
15+
16+
class ResolverInterface extends Type {
17+
ResolverInterface() {
18+
this.getQualifiedName().matches("%Resolver") and
19+
this.getEntity().getDeclaration().getFile() instanceof GqlgenGeneratedFile
20+
}
21+
}
22+
23+
class ResolverInterfaceMethod extends Method {
24+
ResolverInterfaceMethod() {
25+
this.getReceiver().getType() instanceof ResolverInterface
26+
}
27+
}
28+
29+
class ResolverImplementationMethod extends Method {
30+
ResolverImplementationMethod() { this.implements(any(ResolverInterfaceMethod r)) }
31+
32+
Parameter getAnUntrustedParameter() {
33+
result.getFunction() = this.getFuncDecl() and
34+
not result.getType().hasQualifiedName("context", "Context") and
35+
result.getIndex() > 0
36+
}
37+
}
38+
39+
class ResolverParameter extends UntrustedFlowSource::Range instanceof DataFlow::ParameterNode {
40+
ResolverParameter() {
41+
this.asParameter() = any(ResolverImplementationMethod h).getAnUntrustedParameter()
42+
}
43+
}
44+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module pwntester/gqlgen-todos
2+
3+
go 1.19
4+
5+
require (
6+
github.com/99designs/gqlgen v0.17.34
7+
github.com/vektah/gqlparser/v2 v2.5.4
8+
)
9+
10+
require (
11+
github.com/agnivade/levenshtein v1.1.1 // indirect
12+
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
13+
github.com/gorilla/websocket v1.5.0 // indirect
14+
github.com/hashicorp/golang-lru/v2 v2.0.3 // indirect
15+
github.com/mitchellh/mapstructure v1.5.0 // indirect
16+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
17+
github.com/urfave/cli/v2 v2.25.5 // indirect
18+
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
19+
golang.org/x/mod v0.10.0 // indirect
20+
golang.org/x/sys v0.8.0 // indirect
21+
golang.org/x/text v0.9.0 // indirect
22+
golang.org/x/tools v0.9.3 // indirect
23+
gopkg.in/yaml.v3 v3.0.1 // indirect
24+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import go
2+
import semmle.go.frameworks.Gqlgen
3+
4+
from Gqlgen::ResolverParameter p
5+
select p
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Where are all the schema files located? globs are supported eg src/**/*.graphqls
2+
schema:
3+
- graph/*.graphqls
4+
5+
# Where should the generated server code go?
6+
exec:
7+
filename: graph/generated.go
8+
package: graph
9+
10+
# Uncomment to enable federation
11+
# federation:
12+
# filename: graph/federation.go
13+
# package: graph
14+
15+
# Where should any generated models go?
16+
model:
17+
filename: graph/model/models_gen.go
18+
package: model
19+
20+
# Where should the resolver implementations go?
21+
resolver:
22+
layout: follow-schema
23+
dir: graph
24+
package: graph
25+
filename_template: "{name}.resolvers.go"
26+
# Optional: turn on to not generate template comments above resolvers
27+
# omit_template_comment: false
28+
29+
# Optional: turn on use ` + "`" + `gqlgen:"fieldName"` + "`" + ` tags in your models
30+
# struct_tag: json
31+
32+
# Optional: turn on to use []Thing instead of []*Thing
33+
# omit_slice_element_pointers: false
34+
35+
# Optional: turn on to omit Is<Name>() methods to interface and unions
36+
# omit_interface_checks : true
37+
38+
# Optional: turn on to skip generation of ComplexityRoot struct content and Complexity function
39+
# omit_complexity: false
40+
41+
# Optional: turn on to not generate any file notice comments in generated files
42+
# omit_gqlgen_file_notice: false
43+
44+
# Optional: turn on to exclude the gqlgen version in the generated file notice. No effect if `omit_gqlgen_file_notice` is true.
45+
# omit_gqlgen_version_in_file_notice: false
46+
47+
# Optional: turn off to make struct-type struct fields not use pointers
48+
# e.g. type Thing struct { FieldA OtherThing } instead of { FieldA *OtherThing }
49+
# struct_fields_always_pointers: true
50+
51+
# Optional: turn off to make resolvers return values instead of pointers for structs
52+
# resolvers_always_return_pointers: true
53+
54+
# Optional: turn on to return pointers instead of values in unmarshalInput
55+
# return_pointers_in_unmarshalinput: false
56+
57+
# Optional: wrap nullable input fields with Omittable
58+
# nullable_input_omittable: true
59+
60+
# Optional: set to speed up generation time by not performing a final validation pass.
61+
# skip_validation: true
62+
63+
# Optional: set to skip running `go mod tidy` when generating server code
64+
# skip_mod_tidy: true
65+
66+
# gqlgen will search for any type names in the schema in these go packages
67+
# if they match it will use them, otherwise it will generate them.
68+
autobind:
69+
# - "pwntester/gqlgen-todos/graph/model"
70+
71+
# This section declares type mapping between the GraphQL and go type systems
72+
#
73+
# The first line in each type will be used as defaults for resolver arguments and
74+
# modelgen, the others will be allowed when binding to fields. Configure them to
75+
# your liking
76+
models:
77+
ID:
78+
model:
79+
- github.com/99designs/gqlgen/graphql.ID
80+
- github.com/99designs/gqlgen/graphql.Int
81+
- github.com/99designs/gqlgen/graphql.Int64
82+
- github.com/99designs/gqlgen/graphql.Int32
83+
Int:
84+
model:
85+
- github.com/99designs/gqlgen/graphql.Int
86+
- github.com/99designs/gqlgen/graphql.Int64
87+
- github.com/99designs/gqlgen/graphql.Int32

0 commit comments

Comments
 (0)