-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1e31fa
commit a7061db
Showing
16 changed files
with
2,146 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
""" | ||
A point in time, encoded per RFC-3999. Typically these will be in second precision, | ||
just like the blockchain, and in UTC. | ||
""" | ||
scalar Time | ||
|
||
""" | ||
This directive on an input object indicates that a client must specify one of the | ||
fields of the object and no others. Typically used for lookups. | ||
""" | ||
directive @oneOf on INPUT_OBJECT | ||
|
||
""" | ||
The root query type for the GraphQL schema. | ||
""" | ||
type Query { | ||
""" | ||
View a particular node. | ||
""" | ||
node( | ||
""" | ||
The ID of the node. | ||
""" | ||
id: ID! | ||
): Node | ||
|
||
dimo(dimoID: ID!, timeStamp: Time!): Dimo | ||
|
||
dimos( | ||
""" | ||
The number of dimos to retrieve. | ||
Mutually exclusive with `last`. | ||
""" | ||
first: Int | ||
""" | ||
A cursor for pagination. Retrieve dimos after this cursor. | ||
""" | ||
after: String | ||
""" | ||
The number of dimos to retrieve from the end of the list. | ||
Mutually exclusive with `first`. | ||
""" | ||
last: Int | ||
""" | ||
A cursor for pagination. Retrieve dimos before this cursor. | ||
""" | ||
before: String | ||
""" | ||
Filter the dimos based on specific criteria. | ||
""" | ||
filterBy: DimosFilter | ||
): DimoConnection | ||
} | ||
|
||
""" | ||
The DimosFilter input is used to specify filtering criteria for querying dimos. | ||
Dimos must match all of the specified criteria. | ||
""" | ||
input DimosFilter { | ||
tokenID: ID! | ||
since: Time! | ||
until: Time! | ||
} | ||
|
||
# Shared Types | ||
interface Node { | ||
id: ID! | ||
} | ||
|
||
type Dimo implements Node { | ||
id: ID! | ||
tokenID: ID! | ||
timeStamp: Time! | ||
value: String! | ||
} | ||
|
||
type DimoConnection { | ||
totalCount: Int! | ||
edges: [DimoEdge!]! | ||
pageInfo: PageInfo! | ||
} | ||
|
||
type PageInfo { | ||
startCursor: String | ||
endCursor: String | ||
hasPreviousPage: Boolean! | ||
hasNextPage: Boolean! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Code generated by "model-garage" DO NOT EDIT. | ||
package {{ .PackageName }} | ||
|
||
import ( | ||
_ "embed" | ||
) | ||
|
||
// {{ .ModelName }} is the SQL query to create a clickhouse table for the {{ .ModelName }} model. | ||
// | ||
//go:embed {{ schemaFile }} | ||
var {{ .ModelName }}GraphSchema string | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
type {{ lower .ModelName }} implments Node { | ||
{{- range .Signals }} | ||
""" | ||
{{ .Desc }} | ||
""" | ||
{{ .JSONName }}: {{ .GQLType }} | ||
@requiresPrivilege(privileges: {VehicleNonLocationData: null}) | ||
{{- end }} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Package graphql provides the Graphql table generation functionality for converting VSPEC signals to Go structs and Graphql tables. | ||
package graphql | ||
|
||
import ( | ||
"bytes" | ||
_ "embed" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"text/template" | ||
|
||
"github.com/DIMO-Network/model-garage/internal/codegen" | ||
) | ||
|
||
// graphqlFileName is the name of the Graphql table file that will be generated. | ||
var graphqlFileName = "%s-gql.graphql" | ||
|
||
var goGraphqlFileName = "%s-gql.go" | ||
|
||
//go:embed gql.tmpl | ||
var graphqlTableTemplate string | ||
|
||
//go:embed goTable.tmpl | ||
var goGraphqlTableTemplate string | ||
|
||
// Generate creates a new Graphql table file. | ||
func Generate(tmplData *codegen.TemplateData, outputDir string) error { | ||
setFileNamesFrom(tmplData.ModelName) | ||
|
||
// create a new Graphql table template. | ||
graphqlTableTmpl, err := createGraphqlTableTemplate() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// execute the Graphql table template directly to a file. | ||
tablePath := filepath.Clean((filepath.Join(outputDir, graphqlFileName))) | ||
graphqlTableOutputFile, err := os.Create(tablePath) | ||
if err != nil { | ||
return fmt.Errorf("error creating Graphql table output file: %w", err) | ||
} | ||
defer func() { | ||
if cerr := graphqlTableOutputFile.Close(); err == nil && cerr != nil { | ||
err = cerr | ||
} | ||
}() | ||
|
||
err = graphqlTableTmpl.Execute(graphqlTableOutputFile, &tmplData) | ||
if err != nil { | ||
return fmt.Errorf("error executing Graphql table template: %w", err) | ||
} | ||
|
||
// create a new go Graphql table template. | ||
goGraphqlTableTmpl, err := createGoGraphqlTableTemplate() | ||
if err != nil { | ||
return err | ||
} | ||
var outBuf bytes.Buffer | ||
if err = goGraphqlTableTmpl.Execute(&outBuf, &tmplData); err != nil { | ||
return fmt.Errorf("error executing go Graphql table template: %w", err) | ||
} | ||
filePath := filepath.Clean(filepath.Join(outputDir, goGraphqlFileName)) | ||
err = codegen.FormatAndWriteToFile(outBuf.Bytes(), filePath) | ||
if err != nil { | ||
return fmt.Errorf("error writing file: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func setFileNamesFrom(modelName string) { | ||
lowerName := strings.ToLower(modelName) | ||
graphqlFileName = fmt.Sprintf(graphqlFileName, lowerName) | ||
goGraphqlFileName = fmt.Sprintf(goGraphqlFileName, lowerName) | ||
} | ||
|
||
func createGraphqlTableTemplate() (*template.Template, error) { | ||
tmpl, err := template.New("graphqlTableTemplate").Funcs(template.FuncMap{ | ||
"escapeDesc": func(desc string) string { return strings.ReplaceAll(desc, `'`, `\'`) }, | ||
"lower": strings.ToLower, | ||
}).Parse(graphqlTableTemplate) | ||
if err != nil { | ||
return nil, fmt.Errorf("error parsing Graphql table template: %w", err) | ||
} | ||
return tmpl, nil | ||
} | ||
|
||
func createGoGraphqlTableTemplate() (*template.Template, error) { | ||
tmpl, err := template.New("goGraphqlTableTemplate").Funcs(template.FuncMap{ | ||
"schemaFile": func() string { return graphqlFileName }, | ||
}).Parse(goGraphqlTableTemplate) | ||
if err != nil { | ||
return nil, fmt.Errorf("error parsing Graphql table template: %w", err) | ||
} | ||
return tmpl, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.