Ejemplo n.º 1
0
 def select_field(query, *, args):
     if args.first < 0:
         raise g.GraphError(
             "first must be non-negative integer, was {}".format(
                 args.first))
     else:
         return ConnectionQuery(type_query=query,
                                first=args.first,
                                after=args.after)
Ejemplo n.º 2
0
 def read_result(self, value):
     if len(value) == 0:
         return None
     elif len(value) == 1:
         return value[0]
     else:
         raise g.GraphError(
             "expected exactly zero or one values but got {}".format(
                 len(value)))
Ejemplo n.º 3
0
    def read_results(self, iterable):
        result = collections.defaultdict(lambda: None)

        for key, value in iterable:
            if key in result:
                raise g.GraphError("expected exactly zero or one values")
            else:
                result[key] = value

        return result
Ejemplo n.º 4
0
    def read_results(self, iterable):
        result = {}

        for key, value in iterable:
            if key in result:
                raise g.GraphError("expected exactly one value")
            else:
                result[key] = value

        return result
Ejemplo n.º 5
0
 def get_field(field_query):
     if field_query.field == schema.typename_field and isinstance(
             query.type, schema.ObjectType):
         return _ConstantField(query.type.name)
     else:
         field = fields().get(field_query.field)
         if field is None:
             raise g.GraphError("Resolver missing for field {}".format(
                 field_query.field.name))
         elif callable(field):
             # TODO: test dependencies are injected
             return injector.call_with_dependencies(
                 field, graph, field_query)
         else:
             return field
Ejemplo n.º 6
0
 def root_resolve_value(graph, query, args):
     raise g.GraphError("BAD")