-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Align support for multiple operation-files and multiple schema-files #137
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,20 +16,30 @@ import ( | |
"github.com/vektah/gqlparser/v2/validator" | ||
) | ||
|
||
func getSchema(filePatterns StringList) (*ast.Schema, error) { | ||
sources, err := loadSchemaSources(filePatterns) | ||
func getSchema(globs StringList) (*ast.Schema, error) { | ||
filenames, err := expandFilenames(globs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
sources := make([]*ast.Source, len(filenames)) | ||
for i, filename := range filenames { | ||
text, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
return nil, errorf(nil, "unreadable schema file %v: %v", filename, err) | ||
} | ||
sources[i] = &ast.Source{Name: filename, Input: string(text)} | ||
} | ||
|
||
schema, graphqlError := gqlparser.LoadSchema(sources...) | ||
if graphqlError != nil { | ||
filename, _ := graphqlError.Extensions["file"].(string) | ||
return nil, errorf(nil, "invalid schema file %v: %v", filename, graphqlError) | ||
return nil, errorf(nil, "invalid schema: %v", graphqlError) | ||
Comment on lines
-26
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing file name from error message will make it really hard to find issues in schema or operation files. Since we still do not have strong IDE support for graphql SDL files. WDYT? |
||
} | ||
|
||
return schema, nil | ||
} | ||
|
||
func getAndValidateQueries(basedir string, filenames []string, schema *ast.Schema) (*ast.QueryDocument, error) { | ||
func getAndValidateQueries(basedir string, filenames StringList, schema *ast.Schema) (*ast.QueryDocument, error) { | ||
queryDoc, err := getQueries(basedir, filenames) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -44,7 +54,25 @@ func getAndValidateQueries(basedir string, filenames []string, schema *ast.Schem | |
return queryDoc, nil | ||
} | ||
|
||
func getQueries(basedir string, filenames []string) (*ast.QueryDocument, error) { | ||
func expandFilenames(globs []string) ([]string, error) { | ||
uniqFilenames := make(map[string]bool, len(globs)) | ||
for _, glob := range globs { | ||
matches, err := filepath.Glob(glob) | ||
if err != nil { | ||
return nil, errorf(nil, "can't expand file-glob %v: %v", glob, err) | ||
} | ||
for _, match := range matches { | ||
uniqFilenames[match] = true | ||
} | ||
} | ||
filenames := make([]string, 0, len(uniqFilenames)) | ||
for filename := range uniqFilenames { | ||
filenames = append(filenames, filename) | ||
} | ||
return filenames, nil | ||
} | ||
|
||
func getQueries(basedir string, globs StringList) (*ast.QueryDocument, error) { | ||
// We merge all the queries into a single query-document, since operations | ||
// in one might reference fragments in another. | ||
// | ||
|
@@ -57,16 +85,12 @@ func getQueries(basedir string, filenames []string) (*ast.QueryDocument, error) | |
mergedQueryDoc.Fragments = append(mergedQueryDoc.Fragments, queryDoc.Fragments...) | ||
} | ||
|
||
expandedFilenames := make([]string, 0, len(filenames)) | ||
for _, filename := range filenames { | ||
matches, err := filepath.Glob(filename) | ||
if err != nil { | ||
return nil, errorf(nil, "can't expand file-glob %v: %v", filename, err) | ||
} | ||
expandedFilenames = append(expandedFilenames, matches...) | ||
filenames, err := expandFilenames(globs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, filename := range expandedFilenames { | ||
for _, filename := range filenames { | ||
text, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
return nil, errorf(nil, "unreadable query-spec file %v: %v", filename, err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
testdata/errors/InvalidSchema.schema.graphql:4: invalid schema file testdata/errors/InvalidSchema.schema.graphql: Expected :, found } | ||
testdata/errors/InvalidSchema.schema.graphql:4: invalid schema: Expected :, found } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finding the exact issue will be tough just by seeing the new error message. Previous message was better IMO. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the filename is still there, just in a different place:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opps, sorry I missed it. LGTM now! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
testdata/errors/InvalidSchema.schema.graphql:4: invalid schema file testdata/errors/InvalidSchema.schema.graphql: Expected :, found } | ||
testdata/errors/InvalidSchema.schema.graphql:4: invalid schema: Expected :, found } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably get rid of the
Has
function too.