mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-29 11:16:30 +03:00
Feb 15th 2023 update
This commit is contained in:
1
external/graphqlparser/go/.gitignore
vendored
Normal file
1
external/graphqlparser/go/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
go
|
20
external/graphqlparser/go/README.md
vendored
Normal file
20
external/graphqlparser/go/README.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
# About
|
||||
This directory contains an example using the libgraphqlparser C library from [Go](https://golang.org/project/).
|
||||
|
||||
For an overview of binding to C libraries in Go, please see the [cgo documentation](https://github.com/golang/go/wiki/cgo).
|
||||
Specifically, please read the overview of [Function pointer callbacks](https://github.com/golang/go/wiki/cgo#function-pointer-callbacks) in Go and C.
|
||||
|
||||
## Building and Running
|
||||
|
||||
To build with Go, please ensure that you have `pkg-config` installed for your
|
||||
system.
|
||||
|
||||
Assuming pkg-config has been installed, it should be possible to then build
|
||||
using Go in the normal fashion:
|
||||
```sh
|
||||
$ cd libgraphqlparser/go
|
||||
$ go build
|
||||
$ ./go
|
||||
field : myfield
|
||||
Example error: 1.18-19: syntax error, unexpected on, expecting ( or @ or {
|
||||
```
|
18
external/graphqlparser/go/callbacks.go
vendored
Normal file
18
external/graphqlparser/go/callbacks.go
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright 2019-present, GraphQL Foundation
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
package main
|
||||
|
||||
/*
|
||||
struct GraphQLAstField;
|
||||
|
||||
int printField(struct GraphQLAstField *field, void *unused);
|
||||
|
||||
int printField_cgo(struct GraphQLAstField *field, void *unused) {
|
||||
return printField(field, unused);
|
||||
}
|
||||
*/
|
||||
import "C"
|
64
external/graphqlparser/go/gotest.go
vendored
Normal file
64
external/graphqlparser/go/gotest.go
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Copyright 2019-present, GraphQL Foundation
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
package main
|
||||
|
||||
/*
|
||||
#cgo pkg-config: libgraphqlparser
|
||||
|
||||
#include "c/GraphQLAst.h"
|
||||
#include "c/GraphQLAstNode.h"
|
||||
#include "c/GraphQLAstVisitor.h"
|
||||
#include "c/GraphQLParser.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int printField_cgo(struct GraphQLAstField *field, void *unused);
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import "errors"
|
||||
import "fmt"
|
||||
import "unsafe"
|
||||
|
||||
//export printField
|
||||
func printField(field *C.struct_GraphQLAstField, unused unsafe.Pointer) int {
|
||||
fmt.Printf("field : %s\n", C.GoString(C.GraphQLAstName_get_value(C.GraphQLAstField_get_name(field))))
|
||||
return 0
|
||||
}
|
||||
|
||||
func parse(query string) (*C.struct_GraphQLAstNode, error) {
|
||||
graphql := C.CString(query)
|
||||
cError := (*C.char)(nil)
|
||||
ast := C.graphql_parse_string(graphql, &cError)
|
||||
C.free(unsafe.Pointer(graphql))
|
||||
|
||||
if ast == nil {
|
||||
err := errors.New(C.GoString(cError))
|
||||
C.graphql_error_free(cError)
|
||||
return nil, err
|
||||
}
|
||||
return ast, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
ast, err := parse("query myquery { myfield }")
|
||||
if err != nil {
|
||||
fmt.Printf("BUG: unexpected parse error: %s", err)
|
||||
return
|
||||
}
|
||||
visitor_callbacks := C.struct_GraphQLAstVisitorCallbacks{visit_field: (C.visit_field_func)(C.printField_cgo)}
|
||||
C.graphql_node_visit(ast, &visitor_callbacks, nil)
|
||||
|
||||
C.graphql_node_free(ast)
|
||||
|
||||
ast2, err2 := parse("query errorQuery on oops { myfield }")
|
||||
if err2 != nil {
|
||||
fmt.Printf("Example error: %s\n", err2)
|
||||
}
|
||||
if ast2 != nil {
|
||||
fmt.Printf("BUG: we should have got a null AST back, but we got %s\n", ast2)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user