E5F0 Removed deprecated methods in parsing by bbakerman · Pull Request #3509 · graphql-java/graphql-java · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 6 additions & 58 deletions src/main/java/graphql/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,81 +136,29 @@ public Document parseDocument(ParserEnvironment environment) throws InvalidSynta
* @throws InvalidSyntaxException if the input is not valid graphql syntax
*/
public Document parseDocument(String input) throws InvalidSyntaxException {
return parseDocument(input, (ParserOptions) null);
}

/**
* Parses reader input into a graphql AST {@link Document}
*
* @param reader the reader input to parse
*
* @return an AST {@link Document}
*
* @throws InvalidSyntaxException if the input is not valid graphql syntax
*/
public Document parseDocument(Reader reader) throws InvalidSyntaxException {
ParserEnvironment parserEnvironment = ParserEnvironment.newParserEnvironment()
.document(reader)
.build();
return parseDocumentImpl(parserEnvironment);
}

/**
* Parses a string input into a graphql AST {@link Document}
*
* @param input the input to parse
* @param sourceName - the name to attribute to the input text in {@link SourceLocation#getSourceName()}
*
* @return an AST {@link Document}
*
* @throws InvalidSyntaxException if the input is not valid graphql syntax
* @deprecated use {#{@link #parse(ParserEnvironment)}} instead
*/
@Deprecated(since = "2022-08-31")
public Document parseDocument(String input, String sourceName) throws InvalidSyntaxException {
MultiSourceReader multiSourceReader = MultiSourceReader.newMultiSourceReader()
.string(input, sourceName)
.string(input, null)
.trackData(true)
.build();
return parseDocument(multiSourceReader);
}

/**
* Parses a string input into a graphql AST {@link Document}
*
* @param input the input to parse
* @param parserOptions the parser options
*
* @return an AST {@link Document}
*
* @throws InvalidSyntaxException if the input is not valid graphql syntax
* @deprecated use {#{@link #parse(ParserEnvironment)}} instead
*/
@Deprecated(since = "2022-08-31")
public Document parseDocument(String input, ParserOptions parserOptions) throws InvalidSyntaxException {
MultiSourceReader multiSourceReader = MultiSourceReader.newMultiSourceReader()
.string(input, null)
.trackData(true)
ParserEnvironment parserEnvironment = ParserEnvironment.newParserEnvironment()
.document(multiSourceReader)
.build();
return parseDocument(multiSourceReader, parserOptions);
return parseDocumentImpl(parserEnvironment);
}

/**
* Parses reader input into a graphql AST {@link Document}
*
* @param reader the reader input to parse
* @param parserOptions the parser options
* @param reader the reader input to parse
*
* @return an AST {@link Document}
*
* @throws InvalidSyntaxException if the input is not valid graphql syntax
* @deprecated use {#{@link #parse(ParserEnvironment)}} instead
*/
@Deprecated(since = "2022-08-31")
public Document parseDocument(Reader reader, ParserOptions parserOptions) throws InvalidSyntaxException {
public Document parseDocument(Reader reader) throws InvalidSyntaxException {
ParserEnvironment parserEnvironment = ParserEnvironment.newParserEnvironment()
.document(reader)
.parserOptions(parserOptions)
.build();
return parseDocumentImpl(parserEnvironment);
}
Expand Down
6 changes: 4 additions & 2 deletions src/test/groovy/graphql/parser/ParserExceptionTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ fragment X on SomeType {
}
'''
when:
new Parser().parseDocument(sdl, "namedSource")
Reader reader = MultiSourceReader.newMultiSourceReader()
.string(sdl, "namedSource")
.build()
new Parser().parseDocument(reader)
then:
def e = thrown(InvalidSyntaxException)
print e

e.location.line == 2
e.location.column == 13
Expand Down
8 changes: 5 additions & 3 deletions src/test/groovy/graphql/parser/SDLParserTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -800,13 +800,15 @@ input Gun {

when:
def defaultDoc = new Parser().parseDocument(input)
def namedDocNull = new Parser().parseDocument(input, (String) null)
def namedDoc = new Parser().parseDocument(input, sourceName)
Reader reader = MultiSourceReader.newMultiSourceReader()
.string(input, sourceName)
.build();

def namedDoc = new Parser().parseDocument(reader)

then:

defaultDoc.definitions[0].sourceLocation.sourceName == null
namedDocNull.definitions[0].sourceLocation.sourceName == null
namedDoc.definitions[0].sourceLocation.sourceName == sourceName

}
Expand Down
0