Replace try! with ?
This commit is contained in:
parent
05c1011d83
commit
ea3c425f04
14 changed files with 260 additions and 213 deletions
|
@ -432,25 +432,25 @@ impl fmt::Display for InputValue {
|
||||||
InputValue::Enum(ref v) => write!(f, "{}", v),
|
InputValue::Enum(ref v) => write!(f, "{}", v),
|
||||||
InputValue::Variable(ref v) => write!(f, "${}", v),
|
InputValue::Variable(ref v) => write!(f, "${}", v),
|
||||||
InputValue::List(ref v) => {
|
InputValue::List(ref v) => {
|
||||||
try!(write!(f, "["));
|
write!(f, "[")?;
|
||||||
|
|
||||||
for (i, spanning) in v.iter().enumerate() {
|
for (i, spanning) in v.iter().enumerate() {
|
||||||
try!(spanning.item.fmt(f));
|
spanning.item.fmt(f)?;
|
||||||
if i < v.len() - 1 {
|
if i < v.len() - 1 {
|
||||||
try!(write!(f, ", "));
|
write!(f, ", ")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(f, "]")
|
write!(f, "]")
|
||||||
}
|
}
|
||||||
InputValue::Object(ref o) => {
|
InputValue::Object(ref o) => {
|
||||||
try!(write!(f, "{{"));
|
write!(f, "{{")?;
|
||||||
|
|
||||||
for (i, &(ref k, ref v)) in o.iter().enumerate() {
|
for (i, &(ref k, ref v)) in o.iter().enumerate() {
|
||||||
try!(write!(f, "{}: ", k.item));
|
write!(f, "{}: ", k.item)?;
|
||||||
try!(v.item.fmt(f));
|
v.item.fmt(f)?;
|
||||||
if i < o.len() - 1 {
|
if i < o.len() - 1 {
|
||||||
try!(write!(f, ", "));
|
write!(f, ", ")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -220,7 +220,8 @@ impl<'a, T: GraphQLType, C> IntoResolvable<'a, T, C> for FieldResult<(&'a T::Con
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: GraphQLType, C> IntoResolvable<'a, Option<T>, C>
|
impl<'a, T: GraphQLType, C> IntoResolvable<'a, Option<T>, C>
|
||||||
for FieldResult<Option<(&'a T::Context, T)>> {
|
for FieldResult<Option<(&'a T::Context, T)>>
|
||||||
|
{
|
||||||
fn into(self, _: &'a C) -> FieldResult<Option<(&'a T::Context, Option<T>)>> {
|
fn into(self, _: &'a C) -> FieldResult<Option<(&'a T::Context, Option<T>)>> {
|
||||||
self.map(|o| o.map(|(ctx, v)| (ctx, Some(v))))
|
self.map(|o| o.map(|(ctx, v)| (ctx, Some(v))))
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,15 +68,19 @@ pub struct NamedPublic {
|
||||||
#[derive(GraphQLInputObject, Debug)]
|
#[derive(GraphQLInputObject, Debug)]
|
||||||
#[graphql(_internal)]
|
#[graphql(_internal)]
|
||||||
struct FieldDescription {
|
struct FieldDescription {
|
||||||
#[graphql(description = "The first field")] field_one: String,
|
#[graphql(description = "The first field")]
|
||||||
#[graphql(description = "The second field")] field_two: String,
|
field_one: String,
|
||||||
|
#[graphql(description = "The second field")]
|
||||||
|
field_two: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(GraphQLInputObject, Debug)]
|
#[derive(GraphQLInputObject, Debug)]
|
||||||
#[graphql(_internal)]
|
#[graphql(_internal)]
|
||||||
struct FieldWithDefaults {
|
struct FieldWithDefaults {
|
||||||
#[graphql(default = "123")] field_one: i32,
|
#[graphql(default = "123")]
|
||||||
#[graphql(default = "456", description = "The second field")] field_two: i32,
|
field_one: i32,
|
||||||
|
#[graphql(default = "456", description = "The second field")]
|
||||||
|
field_two: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
graphql_object!(Root: () |&self| {
|
graphql_object!(Root: () |&self| {
|
||||||
|
|
|
@ -56,7 +56,8 @@ struct ExampleInputObject {
|
||||||
#[derive(GraphQLInputObject, Debug)]
|
#[derive(GraphQLInputObject, Debug)]
|
||||||
#[graphql(_internal)]
|
#[graphql(_internal)]
|
||||||
struct InputWithDefaults {
|
struct InputWithDefaults {
|
||||||
#[graphql(default = "123")] a: i32,
|
#[graphql(default = "123")]
|
||||||
|
a: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
graphql_object!(TestType: () |&self| {
|
graphql_object!(TestType: () |&self| {
|
||||||
|
|
|
@ -19,7 +19,8 @@ use executor::ExecutionError;
|
||||||
#[derive(Deserialize, Clone, Serialize, PartialEq, Debug)]
|
#[derive(Deserialize, Clone, Serialize, PartialEq, Debug)]
|
||||||
pub struct GraphQLRequest {
|
pub struct GraphQLRequest {
|
||||||
query: String,
|
query: String,
|
||||||
#[serde(rename = "operationName")] operation_name: Option<String>,
|
#[serde(rename = "operationName")]
|
||||||
|
operation_name: Option<String>,
|
||||||
variables: Option<InputValue>,
|
variables: Option<InputValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,22 +102,22 @@ impl<'a> ser::Serialize for GraphQLResponse<'a> {
|
||||||
{
|
{
|
||||||
match self.0 {
|
match self.0 {
|
||||||
Ok((ref res, ref err)) => {
|
Ok((ref res, ref err)) => {
|
||||||
let mut map = try!(serializer.serialize_map(None));
|
let mut map = serializer.serialize_map(None)?;
|
||||||
|
|
||||||
try!(map.serialize_key("data"));
|
map.serialize_key("data")?;
|
||||||
try!(map.serialize_value(res));
|
map.serialize_value(res)?;
|
||||||
|
|
||||||
if !err.is_empty() {
|
if !err.is_empty() {
|
||||||
try!(map.serialize_key("errors"));
|
map.serialize_key("errors")?;
|
||||||
try!(map.serialize_value(err));
|
map.serialize_value(err)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
map.end()
|
map.end()
|
||||||
}
|
}
|
||||||
Err(ref err) => {
|
Err(ref err) => {
|
||||||
let mut map = try!(serializer.serialize_map(Some(1)));
|
let mut map = serializer.serialize_map(Some(1))?;
|
||||||
try!(map.serialize_key("errors"));
|
map.serialize_key("errors")?;
|
||||||
try!(map.serialize_value(err));
|
map.serialize_value(err)?;
|
||||||
map.end()
|
map.end()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,21 +15,21 @@ impl ser::Serialize for ExecutionError {
|
||||||
where
|
where
|
||||||
S: ser::Serializer,
|
S: ser::Serializer,
|
||||||
{
|
{
|
||||||
let mut map = try!(serializer.serialize_map(Some(4)));
|
let mut map = serializer.serialize_map(Some(4))?;
|
||||||
|
|
||||||
try!(map.serialize_key("message"));
|
map.serialize_key("message")?;
|
||||||
try!(map.serialize_value(self.error().message()));
|
map.serialize_value(self.error().message())?;
|
||||||
|
|
||||||
let locations = vec![self.location()];
|
let locations = vec![self.location()];
|
||||||
try!(map.serialize_key("locations"));
|
map.serialize_key("locations")?;
|
||||||
try!(map.serialize_value(&locations));
|
map.serialize_value(&locations)?;
|
||||||
|
|
||||||
try!(map.serialize_key("path"));
|
map.serialize_key("path")?;
|
||||||
try!(map.serialize_value(self.path()));
|
map.serialize_value(self.path())?;
|
||||||
|
|
||||||
if !self.error().data().is_null() {
|
if !self.error().data().is_null() {
|
||||||
try!(map.serialize_key("data"));
|
map.serialize_key("data")?;
|
||||||
try!(map.serialize_value(self.error().data()));
|
map.serialize_value(self.error().data())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
map.end()
|
map.end()
|
||||||
|
@ -123,7 +123,7 @@ impl<'de> de::Deserialize<'de> for InputValue {
|
||||||
{
|
{
|
||||||
let mut values = Vec::new();
|
let mut values = Vec::new();
|
||||||
|
|
||||||
while let Some(el) = try!(visitor.next_element()) {
|
while let Some(el) = visitor.next_element()? {
|
||||||
values.push(el);
|
values.push(el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ impl<'de> de::Deserialize<'de> for InputValue {
|
||||||
{
|
{
|
||||||
let mut values: IndexMap<String, InputValue> = IndexMap::new();
|
let mut values: IndexMap<String, InputValue> = IndexMap::new();
|
||||||
|
|
||||||
while let Some((key, value)) = try!(visitor.next_entry()) {
|
while let Some((key, value)) = visitor.next_entry()? {
|
||||||
values.insert(key, value);
|
values.insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,13 +176,13 @@ impl ser::Serialize for RuleError {
|
||||||
where
|
where
|
||||||
S: ser::Serializer,
|
S: ser::Serializer,
|
||||||
{
|
{
|
||||||
let mut map = try!(serializer.serialize_map(Some(2)));
|
let mut map = serializer.serialize_map(Some(2))?;
|
||||||
|
|
||||||
try!(map.serialize_key("message"));
|
map.serialize_key("message")?;
|
||||||
try!(map.serialize_value(self.message()));
|
map.serialize_value(self.message())?;
|
||||||
|
|
||||||
try!(map.serialize_key("locations"));
|
map.serialize_key("locations")?;
|
||||||
try!(map.serialize_value(self.locations()));
|
map.serialize_value(self.locations())?;
|
||||||
|
|
||||||
map.end()
|
map.end()
|
||||||
}
|
}
|
||||||
|
@ -193,15 +193,15 @@ impl ser::Serialize for SourcePosition {
|
||||||
where
|
where
|
||||||
S: ser::Serializer,
|
S: ser::Serializer,
|
||||||
{
|
{
|
||||||
let mut map = try!(serializer.serialize_map(Some(2)));
|
let mut map = serializer.serialize_map(Some(2))?;
|
||||||
|
|
||||||
let line = self.line() + 1;
|
let line = self.line() + 1;
|
||||||
try!(map.serialize_key("line"));
|
map.serialize_key("line")?;
|
||||||
try!(map.serialize_value(&line));
|
map.serialize_value(&line)?;
|
||||||
|
|
||||||
let column = self.column() + 1;
|
let column = self.column() + 1;
|
||||||
try!(map.serialize_key("column"));
|
map.serialize_key("column")?;
|
||||||
try!(map.serialize_value(&column));
|
map.serialize_value(&column)?;
|
||||||
|
|
||||||
map.end()
|
map.end()
|
||||||
}
|
}
|
||||||
|
@ -212,11 +212,11 @@ impl<'a> ser::Serialize for Spanning<ParseError<'a>> {
|
||||||
where
|
where
|
||||||
S: ser::Serializer,
|
S: ser::Serializer,
|
||||||
{
|
{
|
||||||
let mut map = try!(serializer.serialize_map(Some(2)));
|
let mut map = serializer.serialize_map(Some(2))?;
|
||||||
|
|
||||||
let message = format!("{}", self.item);
|
let message = format!("{}", self.item);
|
||||||
try!(map.serialize_key("message"));
|
map.serialize_key("message")?;
|
||||||
try!(map.serialize_value(&message));
|
map.serialize_value(&message)?;
|
||||||
|
|
||||||
let mut location = IndexMap::new();
|
let mut location = IndexMap::new();
|
||||||
location.insert("line".to_owned(), self.start.line() + 1);
|
location.insert("line".to_owned(), self.start.line() + 1);
|
||||||
|
@ -224,8 +224,8 @@ impl<'a> ser::Serialize for Spanning<ParseError<'a>> {
|
||||||
|
|
||||||
let locations = vec![location];
|
let locations = vec![location];
|
||||||
|
|
||||||
try!(map.serialize_key("locations"));
|
map.serialize_key("locations")?;
|
||||||
try!(map.serialize_value(&locations));
|
map.serialize_value(&locations)?;
|
||||||
|
|
||||||
map.end()
|
map.end()
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,7 +184,7 @@ where
|
||||||
QueryT: GraphQLType<Context = CtxT>,
|
QueryT: GraphQLType<Context = CtxT>,
|
||||||
MutationT: GraphQLType<Context = CtxT>,
|
MutationT: GraphQLType<Context = CtxT>,
|
||||||
{
|
{
|
||||||
let document = try!(parse_document_source(document_source));
|
let document = parse_document_source(document_source)?;
|
||||||
|
|
||||||
{
|
{
|
||||||
let errors = validate_input_values(variables, &document, &root_node.schema);
|
let errors = validate_input_values(variables, &document, &root_node.schema);
|
||||||
|
|
|
@ -11,7 +11,7 @@ use parser::value::parse_value_literal;
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn parse_document_source(s: &str) -> UnlocatedParseResult<Document> {
|
pub fn parse_document_source(s: &str) -> UnlocatedParseResult<Document> {
|
||||||
let mut lexer = Lexer::new(s);
|
let mut lexer = Lexer::new(s);
|
||||||
let mut parser = try!(Parser::new(&mut lexer).map_err(|s| s.map(ParseError::LexerError)));
|
let mut parser = Parser::new(&mut lexer).map_err(|s| s.map(ParseError::LexerError))?;
|
||||||
parse_document(&mut parser)
|
parse_document(&mut parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ fn parse_document<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Docum
|
||||||
let mut defs = Vec::new();
|
let mut defs = Vec::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
defs.push(try!(parse_definition(parser)));
|
defs.push(parse_definition(parser)?);
|
||||||
|
|
||||||
if parser.peek().item == Token::EndOfFile {
|
if parser.peek().item == Token::EndOfFile {
|
||||||
return Ok(defs);
|
return Ok(defs);
|
||||||
|
@ -29,19 +29,17 @@ fn parse_document<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Docum
|
||||||
|
|
||||||
fn parse_definition<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Definition<'a>> {
|
fn parse_definition<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Definition<'a>> {
|
||||||
match parser.peek().item {
|
match parser.peek().item {
|
||||||
Token::CurlyOpen | Token::Name("query") | Token::Name("mutation") => Ok(
|
Token::CurlyOpen | Token::Name("query") | Token::Name("mutation") => {
|
||||||
Definition::Operation(try!(parse_operation_definition(parser))),
|
Ok(Definition::Operation(parse_operation_definition(parser)?))
|
||||||
),
|
}
|
||||||
Token::Name("fragment") => Ok(Definition::Fragment(try!(parse_fragment_definition(
|
Token::Name("fragment") => Ok(Definition::Fragment(parse_fragment_definition(parser)?)),
|
||||||
parser
|
|
||||||
)))),
|
|
||||||
_ => Err(parser.next()?.map(ParseError::UnexpectedToken)),
|
_ => Err(parser.next()?.map(ParseError::UnexpectedToken)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_operation_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Operation<'a>> {
|
fn parse_operation_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Operation<'a>> {
|
||||||
if parser.peek().item == Token::CurlyOpen {
|
if parser.peek().item == Token::CurlyOpen {
|
||||||
let selection_set = try!(parse_selection_set(parser));
|
let selection_set = parse_selection_set(parser)?;
|
||||||
|
|
||||||
Ok(Spanning::start_end(
|
Ok(Spanning::start_end(
|
||||||
&selection_set.start,
|
&selection_set.start,
|
||||||
|
@ -56,14 +54,14 @@ fn parse_operation_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Op
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
let start_pos = parser.peek().start.clone();
|
let start_pos = parser.peek().start.clone();
|
||||||
let operation_type = try!(parse_operation_type(parser));
|
let operation_type = parse_operation_type(parser)?;
|
||||||
let name = match parser.peek().item {
|
let name = match parser.peek().item {
|
||||||
Token::Name(_) => Some(try!(parser.expect_name())),
|
Token::Name(_) => Some(parser.expect_name()?),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let variable_definitions = try!(parse_variable_definitions(parser));
|
let variable_definitions = parse_variable_definitions(parser)?;
|
||||||
let directives = try!(parse_directives(parser));
|
let directives = parse_directives(parser)?;
|
||||||
let selection_set = try!(parse_selection_set(parser));
|
let selection_set = parse_selection_set(parser)?;
|
||||||
|
|
||||||
Ok(Spanning::start_end(
|
Ok(Spanning::start_end(
|
||||||
&start_pos,
|
&start_pos,
|
||||||
|
@ -82,7 +80,7 @@ fn parse_operation_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Op
|
||||||
fn parse_fragment_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Fragment<'a>> {
|
fn parse_fragment_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Fragment<'a>> {
|
||||||
let Spanning {
|
let Spanning {
|
||||||
start: start_pos, ..
|
start: start_pos, ..
|
||||||
} = try!(parser.expect(&Token::Name("fragment")));
|
} = parser.expect(&Token::Name("fragment"))?;
|
||||||
let name = match parser.expect_name() {
|
let name = match parser.expect_name() {
|
||||||
Ok(n) => if n.item == "on" {
|
Ok(n) => if n.item == "on" {
|
||||||
return Err(n.map(|_| ParseError::UnexpectedToken(Token::Name("on"))));
|
return Err(n.map(|_| ParseError::UnexpectedToken(Token::Name("on"))));
|
||||||
|
@ -92,10 +90,10 @@ fn parse_fragment_definition<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Fra
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
};
|
};
|
||||||
|
|
||||||
try!(parser.expect(&Token::Name("on")));
|
parser.expect(&Token::Name("on"))?;
|
||||||
let type_cond = try!(parser.expect_name());
|
let type_cond = parser.expect_name()?;
|
||||||
let directives = try!(parse_directives(parser));
|
let directives = parse_directives(parser)?;
|
||||||
let selection_set = try!(parse_selection_set(parser));
|
let selection_set = parse_selection_set(parser)?;
|
||||||
|
|
||||||
Ok(Spanning::start_end(
|
Ok(Spanning::start_end(
|
||||||
&start_pos,
|
&start_pos,
|
||||||
|
@ -113,7 +111,7 @@ fn parse_optional_selection_set<'a>(
|
||||||
parser: &mut Parser<'a>,
|
parser: &mut Parser<'a>,
|
||||||
) -> OptionParseResult<'a, Vec<Selection<'a>>> {
|
) -> OptionParseResult<'a, Vec<Selection<'a>>> {
|
||||||
if parser.peek().item == Token::CurlyOpen {
|
if parser.peek().item == Token::CurlyOpen {
|
||||||
Ok(Some(try!(parse_selection_set(parser))))
|
Ok(Some(parse_selection_set(parser)?))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
@ -134,14 +132,14 @@ fn parse_fragment<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Selec
|
||||||
let Spanning {
|
let Spanning {
|
||||||
start: ref start_pos,
|
start: ref start_pos,
|
||||||
..
|
..
|
||||||
} = try!(parser.expect(&Token::Ellipsis));
|
} = parser.expect(&Token::Ellipsis)?;
|
||||||
|
|
||||||
match parser.peek().item {
|
match parser.peek().item {
|
||||||
Token::Name("on") => {
|
Token::Name("on") => {
|
||||||
parser.next()?;
|
parser.next()?;
|
||||||
let name = try!(parser.expect_name());
|
let name = parser.expect_name()?;
|
||||||
let directives = try!(parse_directives(parser));
|
let directives = parse_directives(parser)?;
|
||||||
let selection_set = try!(parse_selection_set(parser));
|
let selection_set = parse_selection_set(parser)?;
|
||||||
|
|
||||||
Ok(Selection::InlineFragment(Spanning::start_end(
|
Ok(Selection::InlineFragment(Spanning::start_end(
|
||||||
&start_pos.clone(),
|
&start_pos.clone(),
|
||||||
|
@ -154,7 +152,7 @@ fn parse_fragment<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Selec
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
Token::CurlyOpen => {
|
Token::CurlyOpen => {
|
||||||
let selection_set = try!(parse_selection_set(parser));
|
let selection_set = parse_selection_set(parser)?;
|
||||||
|
|
||||||
Ok(Selection::InlineFragment(Spanning::start_end(
|
Ok(Selection::InlineFragment(Spanning::start_end(
|
||||||
&start_pos.clone(),
|
&start_pos.clone(),
|
||||||
|
@ -167,8 +165,8 @@ fn parse_fragment<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Selec
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
Token::Name(_) => {
|
Token::Name(_) => {
|
||||||
let frag_name = try!(parser.expect_name());
|
let frag_name = parser.expect_name()?;
|
||||||
let directives = try!(parse_directives(parser));
|
let directives = parse_directives(parser)?;
|
||||||
|
|
||||||
Ok(Selection::FragmentSpread(Spanning::start_end(
|
Ok(Selection::FragmentSpread(Spanning::start_end(
|
||||||
&start_pos.clone(),
|
&start_pos.clone(),
|
||||||
|
@ -183,8 +181,8 @@ fn parse_fragment<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Selec
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
Token::At => {
|
Token::At => {
|
||||||
let directives = try!(parse_directives(parser));
|
let directives = parse_directives(parser)?;
|
||||||
let selection_set = try!(parse_selection_set(parser));
|
let selection_set = parse_selection_set(parser)?;
|
||||||
|
|
||||||
Ok(Selection::InlineFragment(Spanning::start_end(
|
Ok(Selection::InlineFragment(Spanning::start_end(
|
||||||
&start_pos.clone(),
|
&start_pos.clone(),
|
||||||
|
@ -201,17 +199,17 @@ fn parse_fragment<'a>(parser: &mut Parser<'a>) -> UnlocatedParseResult<'a, Selec
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_field<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Field<'a>> {
|
fn parse_field<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Field<'a>> {
|
||||||
let mut alias = Some(try!(parser.expect_name()));
|
let mut alias = Some(parser.expect_name()?);
|
||||||
|
|
||||||
let name = if try!(parser.skip(&Token::Colon)).is_some() {
|
let name = if parser.skip(&Token::Colon)?.is_some() {
|
||||||
try!(parser.expect_name())
|
parser.expect_name()?
|
||||||
} else {
|
} else {
|
||||||
alias.take().unwrap()
|
alias.take().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let arguments = try!(parse_arguments(parser));
|
let arguments = parse_arguments(parser)?;
|
||||||
let directives = try!(parse_directives(parser));
|
let directives = parse_directives(parser)?;
|
||||||
let selection_set = try!(parse_optional_selection_set(parser));
|
let selection_set = parse_optional_selection_set(parser)?;
|
||||||
|
|
||||||
Ok(Spanning::start_end(
|
Ok(Spanning::start_end(
|
||||||
&alias.as_ref().unwrap_or(&name).start.clone(),
|
&alias.as_ref().unwrap_or(&name).start.clone(),
|
||||||
|
@ -237,13 +235,11 @@ fn parse_arguments<'a>(parser: &mut Parser<'a>) -> OptionParseResult<'a, Argumen
|
||||||
Ok(None)
|
Ok(None)
|
||||||
} else {
|
} else {
|
||||||
Ok(Some(
|
Ok(Some(
|
||||||
try!(parser.delimited_nonempty_list(
|
parser
|
||||||
&Token::ParenOpen,
|
.delimited_nonempty_list(&Token::ParenOpen, parse_argument, &Token::ParenClose)?
|
||||||
parse_argument,
|
.map(|args| Arguments {
|
||||||
&Token::ParenClose
|
items: args.into_iter().map(|s| s.item).collect(),
|
||||||
)).map(|args| Arguments {
|
}),
|
||||||
items: args.into_iter().map(|s| s.item).collect(),
|
|
||||||
}),
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,9 +247,9 @@ fn parse_arguments<'a>(parser: &mut Parser<'a>) -> OptionParseResult<'a, Argumen
|
||||||
fn parse_argument<'a>(
|
fn parse_argument<'a>(
|
||||||
parser: &mut Parser<'a>,
|
parser: &mut Parser<'a>,
|
||||||
) -> ParseResult<'a, (Spanning<&'a str>, Spanning<InputValue>)> {
|
) -> ParseResult<'a, (Spanning<&'a str>, Spanning<InputValue>)> {
|
||||||
let name = try!(parser.expect_name());
|
let name = parser.expect_name()?;
|
||||||
try!(parser.expect(&Token::Colon));
|
parser.expect(&Token::Colon)?;
|
||||||
let value = try!(parse_value_literal(parser, false));
|
let value = parse_value_literal(parser, false)?;
|
||||||
|
|
||||||
Ok(Spanning::start_end(
|
Ok(Spanning::start_end(
|
||||||
&name.start.clone(),
|
&name.start.clone(),
|
||||||
|
@ -277,13 +273,15 @@ fn parse_variable_definitions<'a>(
|
||||||
Ok(None)
|
Ok(None)
|
||||||
} else {
|
} else {
|
||||||
Ok(Some(
|
Ok(Some(
|
||||||
try!(parser.delimited_nonempty_list(
|
parser
|
||||||
&Token::ParenOpen,
|
.delimited_nonempty_list(
|
||||||
parse_variable_definition,
|
&Token::ParenOpen,
|
||||||
&Token::ParenClose
|
parse_variable_definition,
|
||||||
)).map(|defs| VariableDefinitions {
|
&Token::ParenClose,
|
||||||
items: defs.into_iter().map(|s| s.item).collect(),
|
)?
|
||||||
}),
|
.map(|defs| VariableDefinitions {
|
||||||
|
items: defs.into_iter().map(|s| s.item).collect(),
|
||||||
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,13 +291,13 @@ fn parse_variable_definition<'a>(
|
||||||
) -> ParseResult<'a, (Spanning<&'a str>, VariableDefinition<'a>)> {
|
) -> ParseResult<'a, (Spanning<&'a str>, VariableDefinition<'a>)> {
|
||||||
let Spanning {
|
let Spanning {
|
||||||
start: start_pos, ..
|
start: start_pos, ..
|
||||||
} = try!(parser.expect(&Token::Dollar));
|
} = parser.expect(&Token::Dollar)?;
|
||||||
let var_name = try!(parser.expect_name());
|
let var_name = parser.expect_name()?;
|
||||||
try!(parser.expect(&Token::Colon));
|
parser.expect(&Token::Colon)?;
|
||||||
let var_type = try!(parse_type(parser));
|
let var_type = parse_type(parser)?;
|
||||||
|
|
||||||
let default_value = if try!(parser.skip(&Token::Equals)).is_some() {
|
let default_value = if parser.skip(&Token::Equals)?.is_some() {
|
||||||
Some(try!(parse_value_literal(parser, true)))
|
Some(parse_value_literal(parser, true)?)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
@ -328,7 +326,7 @@ fn parse_directives<'a>(
|
||||||
} else {
|
} else {
|
||||||
let mut items = Vec::new();
|
let mut items = Vec::new();
|
||||||
while parser.peek().item == Token::At {
|
while parser.peek().item == Token::At {
|
||||||
items.push(try!(parse_directive(parser)));
|
items.push(parse_directive(parser)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Spanning::spanning(items))
|
Ok(Spanning::spanning(items))
|
||||||
|
@ -338,9 +336,9 @@ fn parse_directives<'a>(
|
||||||
fn parse_directive<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Directive<'a>> {
|
fn parse_directive<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Directive<'a>> {
|
||||||
let Spanning {
|
let Spanning {
|
||||||
start: start_pos, ..
|
start: start_pos, ..
|
||||||
} = try!(parser.expect(&Token::At));
|
} = parser.expect(&Token::At)?;
|
||||||
let name = try!(parser.expect_name());
|
let name = parser.expect_name()?;
|
||||||
let arguments = try!(parse_arguments(parser));
|
let arguments = parse_arguments(parser)?;
|
||||||
|
|
||||||
Ok(Spanning::start_end(
|
Ok(Spanning::start_end(
|
||||||
&start_pos,
|
&start_pos,
|
||||||
|
@ -355,20 +353,20 @@ fn parse_directive<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Directive<'a>
|
||||||
pub fn parse_type<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Type<'a>> {
|
pub fn parse_type<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, Type<'a>> {
|
||||||
let parsed_type = if let Some(Spanning {
|
let parsed_type = if let Some(Spanning {
|
||||||
start: start_pos, ..
|
start: start_pos, ..
|
||||||
}) = try!(parser.skip(&Token::BracketOpen))
|
}) = parser.skip(&Token::BracketOpen)?
|
||||||
{
|
{
|
||||||
let inner_type = try!(parse_type(parser));
|
let inner_type = parse_type(parser)?;
|
||||||
let Spanning { end: end_pos, .. } = try!(parser.expect(&Token::BracketClose));
|
let Spanning { end: end_pos, .. } = parser.expect(&Token::BracketClose)?;
|
||||||
Spanning::start_end(&start_pos, &end_pos, Type::List(Box::new(inner_type.item)))
|
Spanning::start_end(&start_pos, &end_pos, Type::List(Box::new(inner_type.item)))
|
||||||
} else {
|
} else {
|
||||||
try!(parser.expect_name()).map(|s| Type::Named(Cow::Borrowed(s)))
|
parser.expect_name()?.map(|s| Type::Named(Cow::Borrowed(s)))
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(match *parser.peek() {
|
Ok(match *parser.peek() {
|
||||||
Spanning {
|
Spanning {
|
||||||
item: Token::ExclamationMark,
|
item: Token::ExclamationMark,
|
||||||
..
|
..
|
||||||
} => try!(wrap_non_null(parser, parsed_type)),
|
} => wrap_non_null(parser, parsed_type)?,
|
||||||
_ => parsed_type,
|
_ => parsed_type,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -377,7 +375,7 @@ fn wrap_non_null<'a>(
|
||||||
parser: &mut Parser<'a>,
|
parser: &mut Parser<'a>,
|
||||||
inner: Spanning<Type<'a>>,
|
inner: Spanning<Type<'a>>,
|
||||||
) -> ParseResult<'a, Type<'a>> {
|
) -> ParseResult<'a, Type<'a>> {
|
||||||
let Spanning { end: end_pos, .. } = try!(parser.expect(&Token::ExclamationMark));
|
let Spanning { end: end_pos, .. } = parser.expect(&Token::ExclamationMark)?;
|
||||||
|
|
||||||
let wrapped = match inner.item {
|
let wrapped = match inner.item {
|
||||||
Type::Named(name) => Type::NonNullNamed(name),
|
Type::Named(name) => Type::NonNullNamed(name),
|
||||||
|
|
|
@ -160,10 +160,10 @@ impl<'a> Lexer<'a> {
|
||||||
let start_pos = self.position.clone();
|
let start_pos = self.position.clone();
|
||||||
|
|
||||||
for _ in 0..3 {
|
for _ in 0..3 {
|
||||||
let (_, ch) = try!(self.next_char().ok_or(Spanning::zero_width(
|
let (_, ch) = self.next_char().ok_or(Spanning::zero_width(
|
||||||
&self.position,
|
&self.position,
|
||||||
LexerError::UnexpectedEndOfFile
|
LexerError::UnexpectedEndOfFile,
|
||||||
)));
|
))?;
|
||||||
if ch != '.' {
|
if ch != '.' {
|
||||||
return Err(Spanning::zero_width(
|
return Err(Spanning::zero_width(
|
||||||
&start_pos,
|
&start_pos,
|
||||||
|
@ -181,10 +181,10 @@ impl<'a> Lexer<'a> {
|
||||||
|
|
||||||
fn scan_name(&mut self) -> LexerResult<'a> {
|
fn scan_name(&mut self) -> LexerResult<'a> {
|
||||||
let start_pos = self.position.clone();
|
let start_pos = self.position.clone();
|
||||||
let (start_idx, start_ch) = try!(self.next_char().ok_or(Spanning::zero_width(
|
let (start_idx, start_ch) = self.next_char().ok_or(Spanning::zero_width(
|
||||||
&self.position,
|
&self.position,
|
||||||
LexerError::UnexpectedEndOfFile
|
LexerError::UnexpectedEndOfFile,
|
||||||
)));
|
))?;
|
||||||
assert!(is_name_start(start_ch));
|
assert!(is_name_start(start_ch));
|
||||||
|
|
||||||
let mut end_idx = start_idx;
|
let mut end_idx = start_idx;
|
||||||
|
@ -207,10 +207,10 @@ impl<'a> Lexer<'a> {
|
||||||
|
|
||||||
fn scan_string(&mut self) -> LexerResult<'a> {
|
fn scan_string(&mut self) -> LexerResult<'a> {
|
||||||
let start_pos = self.position.clone();
|
let start_pos = self.position.clone();
|
||||||
let (_, start_ch) = try!(self.next_char().ok_or(Spanning::zero_width(
|
let (_, start_ch) = self.next_char().ok_or(Spanning::zero_width(
|
||||||
&self.position,
|
&self.position,
|
||||||
LexerError::UnexpectedEndOfFile
|
LexerError::UnexpectedEndOfFile,
|
||||||
)));
|
))?;
|
||||||
assert!(start_ch == '"');
|
assert!(start_ch == '"');
|
||||||
|
|
||||||
let mut acc = String::new();
|
let mut acc = String::new();
|
||||||
|
@ -262,7 +262,7 @@ impl<'a> Lexer<'a> {
|
||||||
Some((_, 'u')) => {
|
Some((_, 'u')) => {
|
||||||
let start_pos = self.position.clone();
|
let start_pos = self.position.clone();
|
||||||
self.next_char();
|
self.next_char();
|
||||||
acc.push(try!(self.scan_escaped_unicode(&start_pos)));
|
acc.push(self.scan_escaped_unicode(&start_pos)?);
|
||||||
}
|
}
|
||||||
Some((_, ch)) => {
|
Some((_, ch)) => {
|
||||||
let mut s = String::from("\\");
|
let mut s = String::from("\\");
|
||||||
|
@ -314,18 +314,18 @@ impl<'a> Lexer<'a> {
|
||||||
&mut self,
|
&mut self,
|
||||||
start_pos: &SourcePosition,
|
start_pos: &SourcePosition,
|
||||||
) -> Result<char, Spanning<LexerError>> {
|
) -> Result<char, Spanning<LexerError>> {
|
||||||
let (start_idx, _) = try!(self.peek_char().ok_or(Spanning::zero_width(
|
let (start_idx, _) = self.peek_char().ok_or(Spanning::zero_width(
|
||||||
&self.position,
|
&self.position,
|
||||||
LexerError::UnterminatedString
|
LexerError::UnterminatedString,
|
||||||
)));
|
))?;
|
||||||
let mut end_idx = start_idx;
|
let mut end_idx = start_idx;
|
||||||
let mut len = 0;
|
let mut len = 0;
|
||||||
|
|
||||||
for _ in 0..4 {
|
for _ in 0..4 {
|
||||||
let (idx, ch) = try!(self.next_char().ok_or(Spanning::zero_width(
|
let (idx, ch) = self.next_char().ok_or(Spanning::zero_width(
|
||||||
&self.position,
|
&self.position,
|
||||||
LexerError::UnterminatedString
|
LexerError::UnterminatedString,
|
||||||
)));
|
))?;
|
||||||
|
|
||||||
if !ch.is_alphanumeric() {
|
if !ch.is_alphanumeric() {
|
||||||
break;
|
break;
|
||||||
|
@ -344,12 +344,12 @@ impl<'a> Lexer<'a> {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let code_point = try!(
|
let code_point = u32::from_str_radix(escape, 16).map_err(|_| {
|
||||||
u32::from_str_radix(escape, 16).map_err(|_| Spanning::zero_width(
|
Spanning::zero_width(
|
||||||
start_pos,
|
start_pos,
|
||||||
LexerError::UnknownEscapeSequence("\\u".to_owned() + escape),
|
LexerError::UnknownEscapeSequence("\\u".to_owned() + escape),
|
||||||
))
|
)
|
||||||
);
|
})?;
|
||||||
|
|
||||||
char::from_u32(code_point).ok_or_else(|| {
|
char::from_u32(code_point).ok_or_else(|| {
|
||||||
Spanning::zero_width(
|
Spanning::zero_width(
|
||||||
|
@ -361,14 +361,14 @@ impl<'a> Lexer<'a> {
|
||||||
|
|
||||||
fn scan_number(&mut self) -> LexerResult<'a> {
|
fn scan_number(&mut self) -> LexerResult<'a> {
|
||||||
let start_pos = self.position.clone();
|
let start_pos = self.position.clone();
|
||||||
let int_part = try!(self.scan_integer_part());
|
let int_part = self.scan_integer_part()?;
|
||||||
let mut frac_part = None;
|
let mut frac_part = None;
|
||||||
let mut exp_part = None;
|
let mut exp_part = None;
|
||||||
|
|
||||||
if let Some((_, '.')) = self.peek_char() {
|
if let Some((_, '.')) = self.peek_char() {
|
||||||
self.next_char();
|
self.next_char();
|
||||||
|
|
||||||
frac_part = Some(try!(self.scan_digits()));
|
frac_part = Some(self.scan_digits()?);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some((_, ch)) = self.peek_char() {
|
if let Some((_, ch)) = self.peek_char() {
|
||||||
|
@ -385,7 +385,7 @@ impl<'a> Lexer<'a> {
|
||||||
self.next_char();
|
self.next_char();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exp_part = Some(if is_negative { -1 } else { 1 } * try!(self.scan_digits()));
|
exp_part = Some(if is_negative { -1 } else { 1 } * self.scan_digits()?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,10 +416,10 @@ impl<'a> Lexer<'a> {
|
||||||
|
|
||||||
fn scan_integer_part(&mut self) -> Result<i32, Spanning<LexerError>> {
|
fn scan_integer_part(&mut self) -> Result<i32, Spanning<LexerError>> {
|
||||||
let is_negative = {
|
let is_negative = {
|
||||||
let (_, init_ch) = try!(self.peek_char().ok_or(Spanning::zero_width(
|
let (_, init_ch) = self.peek_char().ok_or(Spanning::zero_width(
|
||||||
&self.position,
|
&self.position,
|
||||||
LexerError::UnexpectedEndOfFile
|
LexerError::UnexpectedEndOfFile,
|
||||||
)));
|
))?;
|
||||||
|
|
||||||
if init_ch == '-' {
|
if init_ch == '-' {
|
||||||
self.next_char();
|
self.next_char();
|
||||||
|
@ -429,10 +429,10 @@ impl<'a> Lexer<'a> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let (_, ch) = try!(self.peek_char().ok_or(Spanning::zero_width(
|
let (_, ch) = self.peek_char().ok_or(Spanning::zero_width(
|
||||||
&self.position,
|
&self.position,
|
||||||
LexerError::UnexpectedEndOfFile
|
LexerError::UnexpectedEndOfFile,
|
||||||
)));
|
))?;
|
||||||
|
|
||||||
if ch == '0' {
|
if ch == '0' {
|
||||||
self.next_char();
|
self.next_char();
|
||||||
|
@ -445,16 +445,16 @@ impl<'a> Lexer<'a> {
|
||||||
_ => Ok(0),
|
_ => Ok(0),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(try!(self.scan_digits()) * if is_negative { -1 } else { 1 })
|
Ok(self.scan_digits()? * if is_negative { -1 } else { 1 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scan_digits(&mut self) -> Result<i32, Spanning<LexerError>> {
|
fn scan_digits(&mut self) -> Result<i32, Spanning<LexerError>> {
|
||||||
let start_pos = self.position.clone();
|
let start_pos = self.position.clone();
|
||||||
let (start_idx, ch) = try!(self.peek_char().ok_or(Spanning::zero_width(
|
let (start_idx, ch) = self.peek_char().ok_or(Spanning::zero_width(
|
||||||
&self.position,
|
&self.position,
|
||||||
LexerError::UnexpectedEndOfFile
|
LexerError::UnexpectedEndOfFile,
|
||||||
)));
|
))?;
|
||||||
let mut end_idx = start_idx;
|
let mut end_idx = start_idx;
|
||||||
|
|
||||||
if !ch.is_digit(10) {
|
if !ch.is_digit(10) {
|
||||||
|
|
|
@ -103,15 +103,15 @@ impl<'a> Parser<'a> {
|
||||||
{
|
{
|
||||||
let Spanning {
|
let Spanning {
|
||||||
start: start_pos, ..
|
start: start_pos, ..
|
||||||
} = try!(self.expect(opening));
|
} = self.expect(opening)?;
|
||||||
let mut items = Vec::new();
|
let mut items = Vec::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Some(Spanning { end: end_pos, .. }) = try!(self.skip(closing)) {
|
if let Some(Spanning { end: end_pos, .. }) = self.skip(closing)? {
|
||||||
return Ok(Spanning::start_end(&start_pos, &end_pos, items));
|
return Ok(Spanning::start_end(&start_pos, &end_pos, items));
|
||||||
}
|
}
|
||||||
|
|
||||||
items.push(try!(parser(self)));
|
items.push(parser(self)?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,13 +128,13 @@ impl<'a> Parser<'a> {
|
||||||
{
|
{
|
||||||
let Spanning {
|
let Spanning {
|
||||||
start: start_pos, ..
|
start: start_pos, ..
|
||||||
} = try!(self.expect(opening));
|
} = self.expect(opening)?;
|
||||||
let mut items = Vec::new();
|
let mut items = Vec::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
items.push(try!(parser(self)));
|
items.push(parser(self)?);
|
||||||
|
|
||||||
if let Some(Spanning { end: end_pos, .. }) = try!(self.skip(closing)) {
|
if let Some(Spanning { end: end_pos, .. }) = self.skip(closing)? {
|
||||||
return Ok(Spanning::start_end(&start_pos, &end_pos, items));
|
return Ok(Spanning::start_end(&start_pos, &end_pos, items));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,13 +153,13 @@ impl<'a> Parser<'a> {
|
||||||
{
|
{
|
||||||
let Spanning {
|
let Spanning {
|
||||||
start: start_pos, ..
|
start: start_pos, ..
|
||||||
} = try!(self.expect(opening));
|
} = self.expect(opening)?;
|
||||||
let mut items = Vec::new();
|
let mut items = Vec::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
items.push(try!(parser(self)));
|
items.push(parser(self)?);
|
||||||
|
|
||||||
if let Some(Spanning { end: end_pos, .. }) = try!(self.skip(closing)) {
|
if let Some(Spanning { end: end_pos, .. }) = self.skip(closing)? {
|
||||||
return Ok(Spanning::start_end(&start_pos, &end_pos, items));
|
return Ok(Spanning::start_end(&start_pos, &end_pos, items));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,33 +63,37 @@ pub fn parse_value_literal<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_list_literal<'a>(parser: &mut Parser<'a>, is_const: bool) -> ParseResult<'a, InputValue> {
|
fn parse_list_literal<'a>(parser: &mut Parser<'a>, is_const: bool) -> ParseResult<'a, InputValue> {
|
||||||
Ok(try!(parser.delimited_list(
|
Ok(parser
|
||||||
&Token::BracketOpen,
|
.delimited_list(
|
||||||
|p| parse_value_literal(p, is_const),
|
&Token::BracketOpen,
|
||||||
&Token::BracketClose
|
|p| parse_value_literal(p, is_const),
|
||||||
)).map(InputValue::parsed_list))
|
&Token::BracketClose,
|
||||||
|
)?
|
||||||
|
.map(InputValue::parsed_list))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_object_literal<'a>(
|
fn parse_object_literal<'a>(
|
||||||
parser: &mut Parser<'a>,
|
parser: &mut Parser<'a>,
|
||||||
is_const: bool,
|
is_const: bool,
|
||||||
) -> ParseResult<'a, InputValue> {
|
) -> ParseResult<'a, InputValue> {
|
||||||
Ok(try!(parser.delimited_list(
|
Ok(parser
|
||||||
&Token::CurlyOpen,
|
.delimited_list(
|
||||||
|p| parse_object_field(p, is_const),
|
&Token::CurlyOpen,
|
||||||
&Token::CurlyClose
|
|p| parse_object_field(p, is_const),
|
||||||
)).map(|items| InputValue::parsed_object(items.into_iter().map(|s| s.item).collect())))
|
&Token::CurlyClose,
|
||||||
|
)?
|
||||||
|
.map(|items| InputValue::parsed_object(items.into_iter().map(|s| s.item).collect())))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_object_field<'a>(
|
fn parse_object_field<'a>(
|
||||||
parser: &mut Parser<'a>,
|
parser: &mut Parser<'a>,
|
||||||
is_const: bool,
|
is_const: bool,
|
||||||
) -> ParseResult<'a, (Spanning<String>, Spanning<InputValue>)> {
|
) -> ParseResult<'a, (Spanning<String>, Spanning<InputValue>)> {
|
||||||
let key = try!(parser.expect_name());
|
let key = parser.expect_name()?;
|
||||||
|
|
||||||
try!(parser.expect(&Token::Colon));
|
parser.expect(&Token::Colon)?;
|
||||||
|
|
||||||
let value = try!(parse_value_literal(parser, is_const));
|
let value = parse_value_literal(parser, is_const)?;
|
||||||
|
|
||||||
Ok(Spanning::start_end(
|
Ok(Spanning::start_end(
|
||||||
&key.start.clone(),
|
&key.start.clone(),
|
||||||
|
@ -101,12 +105,12 @@ fn parse_object_field<'a>(
|
||||||
fn parse_variable_literal<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, InputValue> {
|
fn parse_variable_literal<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, InputValue> {
|
||||||
let Spanning {
|
let Spanning {
|
||||||
start: start_pos, ..
|
start: start_pos, ..
|
||||||
} = try!(parser.expect(&Token::Dollar));
|
} = parser.expect(&Token::Dollar)?;
|
||||||
let Spanning {
|
let Spanning {
|
||||||
item: name,
|
item: name,
|
||||||
end: end_pos,
|
end: end_pos,
|
||||||
..
|
..
|
||||||
} = try!(parser.expect_name());
|
} = parser.expect_name()?;
|
||||||
|
|
||||||
Ok(Spanning::start_end(
|
Ok(Spanning::start_end(
|
||||||
&start_pos,
|
&start_pos,
|
||||||
|
|
|
@ -8,62 +8,85 @@ use types::base::TypeKind;
|
||||||
|
|
||||||
/// Scalar type metadata
|
/// Scalar type metadata
|
||||||
pub struct ScalarMeta<'a> {
|
pub struct ScalarMeta<'a> {
|
||||||
#[doc(hidden)] pub name: Cow<'a, str>,
|
#[doc(hidden)]
|
||||||
#[doc(hidden)] pub description: Option<String>,
|
pub name: Cow<'a, str>,
|
||||||
#[doc(hidden)] pub try_parse_fn: Box<Fn(&InputValue) -> bool + Send + Sync>,
|
#[doc(hidden)]
|
||||||
|
pub description: Option<String>,
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub try_parse_fn: Box<Fn(&InputValue) -> bool + Send + Sync>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// List type metadata
|
/// List type metadata
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ListMeta<'a> {
|
pub struct ListMeta<'a> {
|
||||||
#[doc(hidden)] pub of_type: Type<'a>,
|
#[doc(hidden)]
|
||||||
|
pub of_type: Type<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Nullable type metadata
|
/// Nullable type metadata
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct NullableMeta<'a> {
|
pub struct NullableMeta<'a> {
|
||||||
#[doc(hidden)] pub of_type: Type<'a>,
|
#[doc(hidden)]
|
||||||
|
pub of_type: Type<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Object type metadata
|
/// Object type metadata
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ObjectMeta<'a> {
|
pub struct ObjectMeta<'a> {
|
||||||
#[doc(hidden)] pub name: Cow<'a, str>,
|
#[doc(hidden)]
|
||||||
#[doc(hidden)] pub description: Option<String>,
|
pub name: Cow<'a, str>,
|
||||||
#[doc(hidden)] pub fields: Vec<Field<'a>>,
|
#[doc(hidden)]
|
||||||
#[doc(hidden)] pub interface_names: Vec<String>,
|
pub description: Option<String>,
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub fields: Vec<Field<'a>>,
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub interface_names: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enum type metadata
|
/// Enum type metadata
|
||||||
pub struct EnumMeta<'a> {
|
pub struct EnumMeta<'a> {
|
||||||
#[doc(hidden)] pub name: Cow<'a, str>,
|
#[doc(hidden)]
|
||||||
#[doc(hidden)] pub description: Option<String>,
|
pub name: Cow<'a, str>,
|
||||||
#[doc(hidden)] pub values: Vec<EnumValue>,
|
#[doc(hidden)]
|
||||||
#[doc(hidden)] pub try_parse_fn: Box<Fn(&InputValue) -> bool + Send + Sync>,
|
pub description: Option<String>,
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub values: Vec<EnumValue>,
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub try_parse_fn: Box<Fn(&InputValue) -> bool + Send + Sync>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Interface type metadata
|
/// Interface type metadata
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct InterfaceMeta<'a> {
|
pub struct InterfaceMeta<'a> {
|
||||||
#[doc(hidden)] pub name: Cow<'a, str>,
|
#[doc(hidden)]
|
||||||
#[doc(hidden)] pub description: Option<String>,
|
pub name: Cow<'a, str>,
|
||||||
#[doc(hidden)] pub fields: Vec<Field<'a>>,
|
#[doc(hidden)]
|
||||||
|
pub description: Option<String>,
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub fields: Vec<Field<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Union type metadata
|
/// Union type metadata
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct UnionMeta<'a> {
|
pub struct UnionMeta<'a> {
|
||||||
#[doc(hidden)] pub name: Cow<'a, str>,
|
#[doc(hidden)]
|
||||||
#[doc(hidden)] pub description: Option<String>,
|
pub name: Cow<'a, str>,
|
||||||
#[doc(hidden)] pub of_type_names: Vec<String>,
|
#[doc(hidden)]
|
||||||
|
pub description: Option<String>,
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub of_type_names: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Input object metadata
|
/// Input object metadata
|
||||||
pub struct InputObjectMeta<'a> {
|
pub struct InputObjectMeta<'a> {
|
||||||
#[doc(hidden)] pub name: Cow<'a, str>,
|
#[doc(hidden)]
|
||||||
#[doc(hidden)] pub description: Option<String>,
|
pub name: Cow<'a, str>,
|
||||||
#[doc(hidden)] pub input_fields: Vec<Argument<'a>>,
|
#[doc(hidden)]
|
||||||
#[doc(hidden)] pub try_parse_fn: Box<Fn(&InputValue) -> bool + Send + Sync>,
|
pub description: Option<String>,
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub input_fields: Vec<Argument<'a>>,
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub try_parse_fn: Box<Fn(&InputValue) -> bool + Send + Sync>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A placeholder for not-yet-registered types
|
/// A placeholder for not-yet-registered types
|
||||||
|
@ -72,7 +95,8 @@ pub struct InputObjectMeta<'a> {
|
||||||
/// is inserted into a registry to indicate existence.
|
/// is inserted into a registry to indicate existence.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PlaceholderMeta<'a> {
|
pub struct PlaceholderMeta<'a> {
|
||||||
#[doc(hidden)] pub of_type: Type<'a>,
|
#[doc(hidden)]
|
||||||
|
pub of_type: Type<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generic type metadata
|
/// Generic type metadata
|
||||||
|
@ -92,20 +116,29 @@ pub enum MetaType<'a> {
|
||||||
/// Metadata for a field
|
/// Metadata for a field
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Field<'a> {
|
pub struct Field<'a> {
|
||||||
#[doc(hidden)] pub name: String,
|
#[doc(hidden)]
|
||||||
#[doc(hidden)] pub description: Option<String>,
|
pub name: String,
|
||||||
#[doc(hidden)] pub arguments: Option<Vec<Argument<'a>>>,
|
#[doc(hidden)]
|
||||||
#[doc(hidden)] pub field_type: Type<'a>,
|
pub description: Option<String>,
|
||||||
#[doc(hidden)] pub deprecation_reason: Option<String>,
|
#[doc(hidden)]
|
||||||
|
pub arguments: Option<Vec<Argument<'a>>>,
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub field_type: Type<'a>,
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub deprecation_reason: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Metadata for an argument to a field
|
/// Metadata for an argument to a field
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Argument<'a> {
|
pub struct Argument<'a> {
|
||||||
#[doc(hidden)] pub name: String,
|
#[doc(hidden)]
|
||||||
#[doc(hidden)] pub description: Option<String>,
|
pub name: String,
|
||||||
#[doc(hidden)] pub arg_type: Type<'a>,
|
#[doc(hidden)]
|
||||||
#[doc(hidden)] pub default_value: Option<InputValue>,
|
pub description: Option<String>,
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub arg_type: Type<'a>,
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub default_value: Option<InputValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Metadata for a single value in an enum
|
/// Metadata for a single value in an enum
|
||||||
|
|
|
@ -13,11 +13,16 @@ use schema::meta::{Argument, InterfaceMeta, MetaType, ObjectMeta, PlaceholderMet
|
||||||
/// This brings the mutation and query types together, and provides the
|
/// This brings the mutation and query types together, and provides the
|
||||||
/// predefined metadata fields.
|
/// predefined metadata fields.
|
||||||
pub struct RootNode<'a, QueryT: GraphQLType, MutationT: GraphQLType> {
|
pub struct RootNode<'a, QueryT: GraphQLType, MutationT: GraphQLType> {
|
||||||
#[doc(hidden)] pub query_type: QueryT,
|
#[doc(hidden)]
|
||||||
#[doc(hidden)] pub query_info: QueryT::TypeInfo,
|
pub query_type: QueryT,
|
||||||
#[doc(hidden)] pub mutation_type: MutationT,
|
#[doc(hidden)]
|
||||||
#[doc(hidden)] pub mutation_info: MutationT::TypeInfo,
|
pub query_info: QueryT::TypeInfo,
|
||||||
#[doc(hidden)] pub schema: SchemaType<'a>,
|
#[doc(hidden)]
|
||||||
|
pub mutation_type: MutationT,
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub mutation_info: MutationT::TypeInfo,
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub schema: SchemaType<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Metadata for a schema
|
/// Metadata for a schema
|
||||||
|
|
|
@ -30,7 +30,7 @@ impl Name {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return input.len() > 0;
|
return !input.is_empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue