Skip to content

Commit

Permalink
feat: refactor loader (wundergraph#654)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergiy <818351+devsergiy@users.noreply.github.com>
  • Loading branch information
pvormste and devsergiy committed Nov 1, 2023
1 parent 8900055 commit 27a1266
Show file tree
Hide file tree
Showing 32 changed files with 4,157 additions and 722 deletions.
3 changes: 2 additions & 1 deletion internal/pkg/unsafeparser/unsafeparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
package unsafeparser

import (
"os"

"github.com/TykTechnologies/graphql-go-tools/pkg/ast"
"github.com/TykTechnologies/graphql-go-tools/pkg/astparser"
"os"
)

func ParseGraphqlDocumentString(input string) ast.Document {
Expand Down
5 changes: 3 additions & 2 deletions pkg/execution/datasource/datasource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bytes"
"context"
"encoding/json"
log "github.com/jensneuse/abstractlogger"
"github.com/jensneuse/pipeline/pkg/pipe"
"io"
"os"

log "github.com/jensneuse/abstractlogger"
"github.com/jensneuse/pipeline/pkg/pipe"

"github.com/TykTechnologies/graphql-go-tools/pkg/ast"
"github.com/TykTechnologies/graphql-go-tools/pkg/lexer/literal"
)
Expand Down
5 changes: 3 additions & 2 deletions pkg/imports/graphql_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"testing"

"github.com/jensneuse/diffview"
"github.com/sebdah/goldie"

"github.com/TykTechnologies/graphql-go-tools/pkg/testing/goldie"
)

func TestGraphQLFile_Render(t *testing.T) {
Expand All @@ -24,7 +25,7 @@ func TestGraphQLFile_Render(t *testing.T) {

dump := out.Bytes()

goldie.Assert(t, "render_result", dump)
goldie.Assert(t, "render_result", dump, true)
if t.Failed() {
fixture, err := os.ReadFile("./fixtures/render_result.golden")
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/imports/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package imports
import (
"fmt"
"os"
"path"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -69,7 +68,7 @@ func (s *Scanner) scanFile(inputFilePath string) (*GraphQLFile, error) {
importStatements := importStatementRegex.FindAll(content, -1)
for i := 0; i < len(importStatements); i++ {
importFilePath := s.importFilePath(string(importStatements[i]))
filePathPattern := path.Join(fileDir, importFilePath)
filePathPattern := filepath.Join(fileDir, importFilePath)
if importFilePath != "" {
imports, err := s.fileImportsForPattern(filePathPattern)
if err != nil {
Expand Down
26 changes: 14 additions & 12 deletions pkg/imports/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ package imports
import (
"bytes"
"encoding/json"
"fmt"
"os"
"path/filepath"
"testing"

"github.com/jensneuse/diffview"
"github.com/sebdah/goldie"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/TykTechnologies/graphql-go-tools/pkg/testing/goldie"
)

func TestScanner(t *testing.T) {
Expand All @@ -22,7 +27,7 @@ func TestScanner(t *testing.T) {
t.Fatal(err)
}

goldie.Assert(t, "scanner_result", dump)
goldie.Assert(t, "scanner_result", dump, true)
if t.Failed() {
fixture, err := os.ReadFile("./fixtures/scanner_result.golden")
if err != nil {
Expand All @@ -45,7 +50,7 @@ func TestScanner_ScanRegex(t *testing.T) {
t.Fatal(err)
}

goldie.Assert(t, "scanner_regex", dump)
goldie.Assert(t, "scanner_regex", dump, true)
if t.Failed() {
fixture, err := os.ReadFile("./fixtures/scanner_regex.golden")
if err != nil {
Expand Down Expand Up @@ -74,13 +79,10 @@ func TestScanner_ScanRegex(t *testing.T) {

func TestScannerImportCycle(t *testing.T) {
scanner := Scanner{}
_, err := scanner.ScanFile("./testdata/import_cycle.graphql")
if err == nil {
t.Fatal("want err")
}
want := "file forms import cycle: testdata/cycle/a/a.graphql"
got := err.Error()
if want != got {
t.Fatalf("want err:\n\"%s\"\ngot:\n\"%s\"\n", want, got)
}
file, err := scanner.ScanFile("./testdata/import_cycle.graphql")
_ = file
require.Error(t, err)

cycleFilePath := filepath.Join("testdata", "/cycle/a/a.graphql")
assert.Equal(t, fmt.Sprintf("file forms import cycle: %s", cycleFilePath), err.Error())
}
13 changes: 13 additions & 0 deletions v2/internal/pkg/gocompat/go_1_19.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build !go1.20

package gocompat

import (
"reflect"
"unsafe"
)

func GetUnsafeByteSliceByString(str *string) []byte {
stringHdr := (*reflect.StringHeader)(unsafe.Pointer(str))
return unsafe.Slice((*byte)(unsafe.Pointer(stringHdr.Data)), len(*str))
}
11 changes: 11 additions & 0 deletions v2/internal/pkg/gocompat/go_1_20.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build go1.20

package gocompat

import (
"unsafe"
)

func GetUnsafeByteSliceByString(str *string) []byte {
return unsafe.Slice(unsafe.StringData(*str), len(*str))
}
Loading

0 comments on commit 27a1266

Please sign in to comment.