Skip to content

Commit

Permalink
feat: refactor loader (#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
jensneuse and devsergiy authored Nov 1, 2023
1 parent ddb7fff commit 25af8cf
Show file tree
Hide file tree
Showing 63 changed files with 4,193 additions and 797 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/wundergraph/graphql-go-tools

go 1.18
go 1.20

require (
github.com/99designs/gqlgen v0.17.22
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/unsafeparser/unsafeparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package unsafeparser

import (
"io/ioutil"
"os"

"github.com/wundergraph/graphql-go-tools/pkg/ast"
"github.com/wundergraph/graphql-go-tools/pkg/astparser"
Expand All @@ -25,7 +25,7 @@ func ParseGraphqlDocumentBytes(input []byte) ast.Document {
}

func ParseGraphqlDocumentFile(filePath string) ast.Document {
fileBytes, err := ioutil.ReadFile(filePath)
fileBytes, err := os.ReadFile(filePath)
if err != nil {
panic(err)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/astparser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package astparser

import (
"fmt"
"io/ioutil"
"os"
"testing"

"github.com/wundergraph/graphql-go-tools/pkg/ast"
Expand Down Expand Up @@ -2268,7 +2268,7 @@ func TestErrorReport(t *testing.T) {

func TestParseStarwars(t *testing.T) {

starWarsSchema, err := ioutil.ReadFile("./testdata/starwars.schema.graphql")
starWarsSchema, err := os.ReadFile("./testdata/starwars.schema.graphql")
if err != nil {
t.Fatal(err)
}
Expand All @@ -2282,7 +2282,7 @@ func TestParseStarwars(t *testing.T) {
func TestParseTodo(t *testing.T) {

inputFileName := "./testdata/todo.graphql"
schema, err := ioutil.ReadFile(inputFileName)
schema, err := os.ReadFile(inputFileName)
if err != nil {
t.Fatal(err)
}
Expand All @@ -2298,7 +2298,7 @@ func TestParseTodo(t *testing.T) {
func BenchmarkParseStarwars(b *testing.B) {

inputFileName := "./testdata/starwars.schema.graphql"
starwarsSchema, err := ioutil.ReadFile(inputFileName)
starwarsSchema, err := os.ReadFile(inputFileName)
if err != nil {
b.Fatal(err)
}
Expand All @@ -2325,7 +2325,7 @@ func BenchmarkParseStarwars(b *testing.B) {
func BenchmarkParseGithub(b *testing.B) {

inputFileName := "./testdata/github.schema.graphql"
schemaFile, err := ioutil.ReadFile(inputFileName)
schemaFile, err := os.ReadFile(inputFileName)
if err != nil {
b.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/astprinter/astprinter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package astprinter

import (
"bytes"
"io/ioutil"
"os"
"testing"

"github.com/jensneuse/diffview"
Expand Down Expand Up @@ -521,7 +521,7 @@ func TestPrintSchemaDefinition(t *testing.T) {

goldie.Assert(t, "starwars_schema_definition", out)
if t.Failed() {
fixture, err := ioutil.ReadFile("./fixtures/starwars_schema_definition.golden")
fixture, err := os.ReadFile("./fixtures/starwars_schema_definition.golden")
if err != nil {
t.Fatal(err)
}
Expand All @@ -545,7 +545,7 @@ func TestPrintOperationDefinition(t *testing.T) {

goldie.Assert(t, "introspectionquery", out)
if t.Failed() {
fixture, err := ioutil.ReadFile("./fixtures/introspectionquery.golden")
fixture, err := os.ReadFile("./fixtures/introspectionquery.golden")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/asttransform/baseschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package asttransform

import (
"bytes"
"io/ioutil"
"os"
"testing"

"github.com/jensneuse/diffview"
Expand All @@ -27,7 +27,7 @@ func runTestMerge(definition, fixtureName string) func(t *testing.T) {
got := buf.Bytes()
goldie.Assert(t, fixtureName, got)
if t.Failed() {
want, err := ioutil.ReadFile("./fixtures/" + fixtureName + ".golden")
want, err := os.ReadFile("./fixtures/" + fixtureName + ".golden")
if err != nil {
panic(err)
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/astvalidation/reference/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand All @@ -23,13 +22,13 @@ func main() {
workingDir = filepath.Join(currDir, "pkg/astvalidation/reference/__tests__")
}

dir, err := ioutil.ReadDir(workingDir)
dir, err := os.ReadDir(workingDir)
if err != nil {
log.Fatal(err)
}

replacementsPath := workingDir + "/../replacements.yml"
replacementContent, _ := ioutil.ReadFile(replacementsPath)
replacementContent, _ := os.ReadFile(replacementsPath)

var replacements []Replacement
if err := yaml.Unmarshal(replacementContent, &replacements); err != nil {
Expand Down Expand Up @@ -112,7 +111,7 @@ func skipRule(name string) bool {
// processFile - convert and save reference test file
func processFile(workingDir string, filename string, replacements Replacements) {
fPath := filepath.Join(workingDir, filename)
fileContent, _ := ioutil.ReadFile(fPath)
fileContent, _ := os.ReadFile(fPath)

testName := strings.TrimSuffix(strings.Split(filepath.Base(filename), ".")[0], "-test")

Expand All @@ -129,7 +128,7 @@ func processFile(workingDir string, filename string, replacements Replacements)
result := converter.iterateLines(testName, content)

outFileName := testName + "_test.go"
err := ioutil.WriteFile(filepath.Join(outDir, outFileName), []byte(result), os.ModePerm)
err := os.WriteFile(filepath.Join(outDir, outFileName), []byte(result), os.ModePerm)
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/astvalidation/reference/testsgo/harness_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testsgo

import (
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -314,7 +314,7 @@ func hasReportError(t *testing.T, report operationreport.Report) MessageCompare
var testSchema string

func init() {
content, err := ioutil.ReadFile("test_schema.graphql")
content, err := os.ReadFile("test_schema.graphql")
if err != nil {
panic(err)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/astvisitor/visitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"testing"

"github.com/jensneuse/diffview"
Expand Down Expand Up @@ -45,7 +45,7 @@ func TestVisitOperation(t *testing.T) {

if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/visitor.golden")
fixture, err := os.ReadFile("./fixtures/visitor.golden")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestVisitSchemaDefinition(t *testing.T) {

if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/schema_visitor.golden")
fixture, err := os.ReadFile("./fixtures/schema_visitor.golden")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestWalker_Path(t *testing.T) {

if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/path.golden")
fixture, err := os.ReadFile("./fixtures/path.golden")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -247,7 +247,7 @@ func TestVisitWithSkip(t *testing.T) {

if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/visitor_skip.golden")
fixture, err := os.ReadFile("./fixtures/visitor_skip.golden")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/codegen/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package codegen

import (
"bytes"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestCodeGen_GenerateDirectiveDefinitionStruct(t *testing.T) {
goldie.Assert(t, "DataSource", data)
if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/DataSource.golden")
fixture, err := os.ReadFile("./fixtures/DataSource.golden")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/engine/datasource/rest_datasource/rest_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package rest_datasource
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -1223,7 +1223,7 @@ func TestHttpJsonDataSource_Load(t *testing.T) {

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method)
actualBody, err := ioutil.ReadAll(r.Body)
actualBody, err := io.ReadAll(r.Body)
assert.NoError(t, err)
assert.Equal(t, string(actualBody), body)
_, _ = w.Write([]byte(`ok`))
Expand Down
3 changes: 1 addition & 2 deletions pkg/execution/datasource/datasource_graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"io"
"io/ioutil"
"net/http"

"github.com/buger/jsonparser"
Expand Down Expand Up @@ -440,7 +439,7 @@ func (g *GraphQLDataSource) Resolve(ctx context.Context, args ResolverArgs, out
)
return n, err
}
data, err := ioutil.ReadAll(res.Body)
data, err := io.ReadAll(res.Body)
if err != nil {
g.Log.Error("GraphQLDataSource.ioutil.ReadAll",
log.Error(err),
Expand Down
3 changes: 1 addition & 2 deletions pkg/execution/datasource/datasource_http_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"strconv"

Expand Down Expand Up @@ -336,7 +335,7 @@ func (r *HttpJsonDataSource) Resolve(ctx context.Context, args ResolverArgs, out
return
}

data, err := ioutil.ReadAll(res.Body)
data, err := io.ReadAll(res.Body)
if err != nil {
r.Log.Error("HttpJsonDataSource.Resolve.ioutil.ReadAll",
log.Error(err),
Expand Down
3 changes: 1 addition & 2 deletions pkg/execution/datasource/datasource_http_polling_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"strings"
"sync"
Expand Down Expand Up @@ -188,7 +187,7 @@ func (h *HttpPollingStreamDataSource) startPolling(ctx context.Context) {
)
return
}
data, err = ioutil.ReadAll(response.Body)
data, err = io.ReadAll(response.Body)
if err != nil {
h.Log.Error("HttpPollingStreamDataSource.startPolling.ioutil.ReadAll",
log.Error(err),
Expand Down
4 changes: 2 additions & 2 deletions pkg/execution/datasource/datasource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"io"
"io/ioutil"
"os"

log "github.com/jensneuse/abstractlogger"
"github.com/jensneuse/pipeline/pkg/pipe"
Expand Down Expand Up @@ -112,7 +112,7 @@ func (h *PipelineDataSourcePlanner) LeaveField(ref int) {
}
if h.dataSourceConfig.ConfigFilePath != nil {
var err error
h.rawPipelineConfig, err = ioutil.ReadFile(*h.dataSourceConfig.ConfigFilePath)
h.rawPipelineConfig, err = os.ReadFile(*h.dataSourceConfig.ConfigFilePath)
if err != nil {
h.Log.Error("PipelineDataSourcePlanner.readConfigFile", log.Error(err))
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/execution/datasource_graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -239,7 +239,7 @@ func upstreamGraphqlServer(t *testing.T, assertRequestBody bool, expectedRequest
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.NotNil(t, r.Body)

bodyBytes, err := ioutil.ReadAll(r.Body)
bodyBytes, err := io.ReadAll(r.Body)
require.NoError(t, err)

if assertRequestBody {
Expand Down
4 changes: 2 additions & 2 deletions pkg/execution/datasource_http_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -844,7 +844,7 @@ func upstreamHttpJsonServer(t *testing.T, assertRequestBody bool, expectedReques
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.NotNil(t, r.Body)

bodyBytes, err := ioutil.ReadAll(r.Body)
bodyBytes, err := io.ReadAll(r.Body)
require.NoError(t, err)

if assertRequestBody {
Expand Down
3 changes: 1 addition & 2 deletions pkg/graphql/execution_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"sync"

Expand Down Expand Up @@ -163,7 +162,7 @@ func (r *ExecutionResult) GetAsHTTPResponse() (res *http.Response) {
}

res = &http.Response{}
res.Body = ioutil.NopCloser(r.buf)
res.Body = io.NopCloser(r.buf)
res.Header = make(http.Header)
res.StatusCode = 200

Expand Down
Loading

0 comments on commit 25af8cf

Please sign in to comment.