예제 #1
0
파일: sql_test.go 프로젝트: sevki/g2sd
func TestQuery(t *testing.T) {

	db, err := sqlx.Open("sqlite3", "./test_db.db")
	if err != nil {
		t.Fatal(err)
	}

	const q = `{
  Products(ProductID: 3) {
    ProductName,
    UnitsInStock,
    CategoryId,
    Categories() {
       CategoryName
    }
  }
}`
	if ast, err := parse.NewQuery([]byte(q)); err != nil {
		t.Error(err.Error())
	} else {
		log.Println(prettyprint.AsJSON(d(ast, db, t)))
	}

	defer db.Close()

}
예제 #2
0
파일: sql_test.go 프로젝트: sevki/g2sd
func TestQueryComplex(t *testing.T) {

	db, err := sqlx.Open("sqlite3", "./test_db.db")
	if err != nil {
		t.Fatal(err)
	}

	const q = `{
  Products(ProductID: 9) {
    ProductName,
    UnitsInStock,
    ProductID,
    OrderDetails(ProductID: $ProductID) {
       OrderID,
       Orders(OrderID: $OrderID) {
         EmployeeID,
         Employees(EmployeeID: $EmployeeID) {
            FirstName
         }
       }
    }
  }
}`
	if ast, err := parse.NewQuery([]byte(q)); err != nil {
		t.Error(err.Error())
	} else {
		log.Println(prettyprint.AsJSON(d(ast, db, t)))
		//d(ast, db, t)
	}

	defer db.Close()

}
예제 #3
0
파일: test.go 프로젝트: tallstreet/graphql
func main() {
	var doc graphql.Document
	fs, _ := os.Open("./tests/relay-todo.graphql")
	if err := parser.New("graphql", fs).Decode(&doc); err != nil {

		log.Printf(err.Error())

	} else {

		log.Printf(prettyprint.AsJSON(doc))
		log.Print(doc.DefinitionSize)
	}

	parser.InlineFragments(&doc)
	log.Printf(prettyprint.AsJSON(doc.Operations[0]))
}
예제 #4
0
func TestParseHarvey(t *testing.T) {

	doc, err := readAndParse("tests/harvey.BUILD")
	if err != nil {
		t.Error(err)
	}
	log.Println(prettyprint.AsJSON(doc))

}
예제 #5
0
파일: main.go 프로젝트: ftrvxmtrx/build
func execute(t string) {

	c := builder.New()

	if c.ProjectPath == "" {
		fmt.Fprintf(os.Stderr, "You need to be in a git project.\n\n")
		printUsage()
	}
	c.Root = c.Add(t)
	c.Root.IsRoot = true

	if c.Root == nil {
		log.Fatal("We couldn't find the root")
	}

	cpus := int(float32(runtime.NumCPU()) * 1.25)

	done := make(chan bool)

	// If the app hangs, there is a log.
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, os.Interrupt)
	go func() {
		<-sigs
		f, _ := os.Create("/tmp/build-crash-log.json")
		fmt.Fprintf(f, prettyprint.AsJSON(c.Root))
		os.Exit(1)
	}()

	go term.Listen(c.Updates, cpus, *verbose)
	go term.Run(done)

	go c.Execute(time.Second, cpus)
	for {
		select {
		case done := <-c.Done:
			if *verbose {
				doneMessage(done.Url.String())
			}
			if done.IsRoot {
				goto FIN
			}
		case err := <-c.Error:
			<-done
			log.Fatal(err)
			os.Exit(1)
		case <-c.Timeout:
			log.Println("your build has timed out")
		}

	}
FIN:
	term.Exit()
	<-done
	os.Exit(0)
}
예제 #6
0
파일: main.go 프로젝트: ftrvxmtrx/build
func query(t string) {

	c := builder.New()

	if c.ProjectPath == "" {
		fmt.Fprintf(os.Stderr, "You need to be in a git project.\n\n")
		printUsage()
	}
	fmt.Println(prettyprint.AsJSON(c.Add(t).Target))
}
예제 #7
0
파일: server.go 프로젝트: ftrvxmtrx/build
func graph(w http.ResponseWriter, r *http.Request) {
	c := builder.New()

	if c.ProjectPath == "" {
		fmt.Fprintf(os.Stderr, "You need to be in a git project.\n\n")
		printUsage()
	}
	c.Add(targetName)

	w.Write([]byte(prettyprint.AsJSON(c.Nodes[targetName])))

}
예제 #8
0
파일: test.go 프로젝트: lessc0de/graphql-1
func main() {
	var doc graphql.Document
	fs, _ := os.Open("./tests/kitchen-sink.graphql")
	if err := parser.New("graphql", fs).Decode(&doc); err != nil {

		log.Printf(err.Error())

	} else {

		log.Printf(prettyprint.AsJSON(doc))
		log.Print(doc.DefinitionSize)
	}
}
예제 #9
0
func TestKitchenSink(t *testing.T) {
	t.Parallel()
	var doc ast.Document
	ks, _ := os.Open("../tests/complex-as-possible.graphql")
	if err := New("kitchenSink", ks).Decode(&doc); err != nil {
		t.Error(err.Error())

		if err != nil {
			t.Error(err)
		}

	} else {
		//		fs, _ := os.Open("../tests/complex-as-possible.graphql")
		//		e, _ := ioutil.ReadAll(fs)
		//		log.Printf(string(e))
		log.Printf(prettyprint.AsJSON(doc))
	}

}
예제 #10
0
파일: cbin.go 프로젝트: ftrvxmtrx/build
func (cb *CBin) Build(c *build.Context) error {
	c.Println(prettyprint.AsJSON(cb))
	params := []string{}
	params = append(params, cb.CompilerOptions...)
	params = append(params, cb.Sources...)

	params = append(params, cb.Includes.Includes()...)

	if err := c.Exec(Compiler(), CCENV, params); err != nil {
		return fmt.Errorf(err.Error())
	}

	ldparams := []string{"-o", cb.Name}
	ldparams = append(ldparams, cb.LinkerOptions...)
	if cb.LinkerFile != "" {
		ldparams = append(ldparams, cb.LinkerFile)
	}
	// This is done under the assumption that each src file put in this thing
	// here will comeout as a .o file
	for _, f := range cb.Sources {
		_, fname := filepath.Split(f)
		ldparams = append(ldparams, fmt.Sprintf("%s.o", fname[:strings.LastIndex(fname, ".")]))
	}

	ldparams = append(ldparams, "-L", "lib")

	for _, dep := range cb.Dependencies {
		d := split(dep, ":")
		if len(d) < 3 {
			continue
		}
		if d[:3] == "lib" {
			ldparams = append(ldparams, fmt.Sprintf("-l%s", d[3:]))
		}
	}

	if err := c.Exec(Linker(), CCENV, ldparams); err != nil {
		return fmt.Errorf(err.Error())
	}

	return nil
}
예제 #11
0
// ServeHTTP provides an entrypoint into a graphql executor. It pulls the query from
// the 'q' GET parameter.
func (h *ExecutorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Access-Control-Allow-Headers", r.Header.Get("Access-Control-Request-Headers"))
	if r.Method == "OPTIONS" {
		w.WriteHeader(200)
		return
	}

	decoder := json.NewDecoder(r.Body)
	var qreq Request
	err := decoder.Decode(&qreq)
	if err != nil {
		log.Println("error parsing:", err)
		writeErr(w, err)
		return
	}
	q := qreq.Query

	/*
		//TODO(tallstreet): reject non-GET/OPTIONS requests
		q := r.URL.Query().Get("q")
	*/
	var doc graphql.Document
	if err := parser.New("graphql", strings.NewReader(q)).Decode(&doc); err != nil {

		log.Printf(err.Error())

	} else {
		//		fs, _ := os.Open("../tests/complex-as-possible.graphql")
		//		e, _ := ioutil.ReadAll(fs)
		//		log.Printf(string(e))
		log.Printf(prettyprint.AsJSON(doc))
	}

	/*
		log.Println("query:", q)
		operation, err := parser.ParseOperation([]byte(q))
		if err != nil {
			log.Println("error parsing:", err)
			writeErr(w, err)
			return
		}
	*/

	operation := doc.Operations[0]
	asjson, _ := json.MarshalIndent(operation, "", " ")
	log.Println(string(asjson))
	// if err := h.validator.Validate(operation); err != nil { writeErr(w, err); return }
	ctx := context.Background()
	if r.Header.Get("X-Trace-ID") != "" {
		t, err := tracer.FromRequest(r)
		if err == nil {
			ctx = tracer.NewContext(ctx, t)
		}
	}
	ctx = context.WithValue(ctx, "http_request", r)
	if r.Header.Get("X-GraphQL-Only-Parse") == "1" {
		writeJSONIndent(w, operation, " ")
		return
	}

	data, err := h.executor.HandleOperation(ctx, operation)
	result := Result{Data: data}
	if err != nil {
		w.WriteHeader(400)
		result.Error = &Error{Message: err.Error()}
	}
	if t, ok := tracer.FromContext(ctx); ok {
		t.Done()
		result.Trace = t
	}
}
예제 #12
0
파일: mksys.go 프로젝트: ftrvxmtrx/build
func (mkSys *MkSys) Build(c *build.Context) error {

	c.Println(prettyprint.AsJSON(mkSys))

	sysconf, err := mkSys.readSysconf()
	if err != nil {
		return err
	}

	syscalls := sysconf.Syscalls
	syserrors := sysconf.Syserrors
	bootmethods := sysconf.Bootmethods
	for i := range syscalls {
		if syscalls[i].Define == "" {
			syscalls[i].Define = strings.ToUpper(syscalls[i].Name)
		}
		if syscalls[i].Sysname == "" {
			syscalls[i].Sysname = "sys" + syscalls[i].Name
		}
		if syscalls[i].Libname == "" {
			syscalls[i].Libname = syscalls[i].Name
		}
	}

	outfile, err := c.Create(mkSys.Mode)
	if err != nil {
		return err
	}
	switch mkSys.Mode {
	case "sys_harvey.s":
		if mkSys.ARCH != "amd64" {
			c.Println("ARCH unsupported or not set")
		}
		syscallargs := []string{"DI", "SI", "DX", "R10", "R8", "R9"}
		//funcallregs := []string{ "DI", "SI", "DX", "CX", "R8", "R9" };
		for i := range syscalls {
			goargs := []string{}
			fpoff := 0
			for k := range syscalls[i].Args {
				switch syscalls[i].Args[k] {
				case "int32_t", "uint32_t":
					goargs = append(goargs, fmt.Sprintf("MOVL	arg%d+%d(FP), %s", k, fpoff, syscallargs[k]))
					fpoff += 4
				case "void*", "char*", "char**", "uint8_t*", "int32_t*", "uint64_t*", "int64_t*", "int64_t":
					fpoff = (fpoff + 7) & ^7
					goargs = append(goargs, fmt.Sprintf("MOVQ	arg%d+%d(FP), %s", k, fpoff, syscallargs[k]))
					fpoff += 8
				default:
					return fmt.Errorf("unsupported arg %s in syscall: %v", syscalls[i].Args[k], syscalls[i])
				}
			}
			syscalls[i].GoArgs = goargs
			switch syscalls[i].Ret[0] {
			case "int32_t", "uint32_t":
				syscalls[i].Ret0 = fmt.Sprintf("MOVL	AX, ret+%d(FP)", fpoff)
				fpoff += 4
			case "void*", "char*", "char**", "uint8_t*", "int32_t*", "uint64_t*", "int64_t*", "int64_t":
				fpoff = (fpoff + 7) & ^7
				syscalls[i].Ret0 = fmt.Sprintf("MOVQ	AX, ret+%d(FP)", fpoff)
				fpoff += 8
			default:
				return fmt.Errorf("unsupported Ret[0] in syscall: %v", syscalls[i])
			}
		}
		tmpl, err := template.New("sys_harvey.s").Parse(`/* automatically generated by mksys */
/* System calls for AMD64, Harvey */
#include "go_asm.h"
#include "go_tls.h"
#include "textflag.h"
{{ range . }}
TEXT runtime·{{ .Libname }}(SB),NOSPLIT,$0
{{ range .GoArgs }}	{{ . }}
{{ end }}	MOVQ	${{ .Id }}, AX
	SYSCALL
	{{ .Ret0 }}
	RET
{{ end }}
`)
		if err != nil {
			return err
		}
		err = tmpl.Execute(outfile, syscalls)
		if err != nil {
			return err
		}

	case "syscallfiles":
		if mkSys.ARCH != "amd64" {
			return fmt.Errorf("ARCH unsupported or not set")
		}
		tmpl, err := template.New("syscall.s").Parse(`/* automatically generated by mksys */
.globl	{{ .Libname }}
{{ .Libname }}:
	movq %rcx, %r10 /* rcx gets smashed by systenter. Use r10.*/
	movq ${{ .Id }},%rax  /* Put the system call into rax, just like linux. */
	syscall
	ret
`)
		if err != nil {
			return err
		}

		for i := range syscalls {

			file, err := c.Create(syscalls[i].Libname + ".s")
			if err != nil {
				return err
			}

			err = tmpl.Execute(file, syscalls[i])
			if err != nil {
				return err
			}

			err = file.Close()
			if err != nil {
				return err
			}
		}
	case "sysnum.go":
		tmpl, err := template.New("sysnum.go").Parse(`// automatically generated by mksys
package syscall
const(
{{ range . }}	SYS_{{ .Define }} = {{ .Id }}
{{ end }}
)
`)
		err = tmpl.Execute(outfile, syscalls)
		if err != nil {
			return err
		}

	case "sys.h":
		tmpl, err := template.New("sys.h").Parse(`/* automatically generated by mksys */
{{ range . }}#define {{ .Define }} {{ .Id }}
{{ end }}
`)
		err = tmpl.Execute(outfile, syscalls)
		if err != nil {
			return err
		}

	case "sysdecl.h":
		tmpl, err := template.New("sysdecl.h").Parse(`/* automatically generated by mksys */
{{ range . }}extern {{ .Ret0 }} {{ .Libname }}({{ range $i, $e := .Args }}{{ if $i }}, {{ end }}{{ $e }}{{ end }});
{{ end }}
`)
		err = tmpl.Execute(outfile, syscalls)
		if err != nil {
			return err
		}

	case "systab.c":
		for i := range syscalls {
			var fudge string
			switch syscalls[i].Ret[0] {
			case "int32_t":
				fudge = "{ .i = -1 }"
			case "int64_t":
				fudge = "{ .vl = -1ll }"
			case "void*", "char*":
				fudge = "{ .v = (void*)-1ll }"
			default:
				return fmt.Errorf("unsupported Ret[0] in syscall: %v", syscalls[i])
			}
			if syscalls[i].Fudge == "" {
				syscalls[i].Fudge = fudge
			}

			syscalls[i].Ret0 = syscalls[i].Ret[0]
		}
		tmpl, err := template.New("systab.c").Parse(`/* automatically generated by mksys */
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include <sys.h>
{{ range . }}extern void {{ .Sysname }}(Ar0*, ...);
{{ end }}
Systab systab[] = {
{{ range . }}[{{ .Define }}] { "{{ .Name }}", {{ .Sysname }}, {{ .Fudge }} },
{{ end }}
};
int nsyscall = nelem(systab);
`)
		err = tmpl.Execute(outfile, syscalls)
		if err != nil {
			return err
		}

	case "error.h":
		tmpl, err := template.New("error.h").Parse(`/* automatically generated by mksys */
{{ range . }}extern char {{ .Name }}[]; /* {{ .String }} */
{{ end }}
`)
		err = tmpl.Execute(outfile, syserrors)
		if err != nil {
			return err
		}

	case "errstr.h":
		tmpl, err := template.New("errstr.h").Parse(`/* automatically generated by mksys */
{{ range . }}char {{ .Name }}[] = "{{ .String }}";
{{ end }}
`)
		err = tmpl.Execute(outfile, syserrors)
		if err != nil {
			return err
		}
	case "bootamd64cpu.c":
		tmpl, err := template.New("bootamd64cpu.c").Parse(`/* automatically generated by mksys */
#include <u.h>
#include <libc.h>
#include <boot.h>
Method method[] = {
{{ range . }}{ "{{.Name}}", {{.Config}}, {{.Connect}}, "{{.Arg}}", },
{{ end }}
	{ nil },
};
int cpuflag = 1;
char* rootdir = "/root";
char* bootdisk = "#S/sdE0/";
extern void boot(int, char**);
void
main(int argc, char **argv)
{
		boot(argc, argv);
}
int (*cfs)(int) = 0;
`)
		err = tmpl.Execute(outfile, bootmethods)
		if err != nil {
			log.Fatal(err)
		}
	}
	return nil
}