Example #1
0
    def generate(self):
        query_classes = []
        mutation_classes = {}

        at_least_one_query_action_exists = False

        for obj in self.objects:
            for name, field in self.convert_output_fields_for_object(
                    obj).items():
                get_class(obj)._meta.fields[name] = field

            for name, field in self.convert_input_fields_for_object(
                    obj).items():
                get_class(obj, input=True)._meta.fields[name] = field

            query_actions, mutation_actions = self.convert_actions(
                obj.actions, obj.__name__)
            if query_actions:
                at_least_one_query_action_exists = True

            query_class = type("Query", (graphene.ObjectType, ), query_actions)
            query_classes.append(query_class)
            self.update_mutation_classes(mutation_actions, mutation_classes)

        query_actions, mutation_actions = self.convert_actions(
            self.extra_actions)

        # if there are no query actions, create a dummy one, since graphene-python needs that
        if not query_actions and not at_least_one_query_action_exists:
            query_actions = {
                "dummy":
                Action(return_value=BooleanType(),
                       exec_fn=Function(
                           lambda request, params: False)).convert(self)
            }

        self.update_mutation_classes(mutation_actions, mutation_classes)

        query_class = type("Query",
                           tuple(query_classes) + (graphene.ObjectType, ),
                           query_actions)

        mutation_class = None
        if mutation_classes:
            mutation_class = type("Mutation", (graphene.ObjectType, ),
                                  mutation_classes)

        check_classes_for_fields()
        return graphene.Schema(query=query_class,
                               mutation=mutation_class,
                               auto_camelcase=False)
Example #2
0
def convert_input_object_type(type, adapter, **kwargs):
    return convert_input_class_type(type, get_class(type.to, input=True),
                                    adapter, **kwargs)
Example #3
0
def convert_output_object_type(type, adapter, **kwargs):
    return convert_output_class_type(type,
                                     get_class(type.to),
                                     adapter,
                                     **kwargs)
def convert_list_output_object_type(type, adapter, **kwargs):
    if type.nullable():
        return get_class(type.to)
    return graphene.NonNull(get_class(type.to))
Example #5
0
def convert_list_input_object_type(type, adapter, **kwargs):
    if type.nullable(input=True):
        return get_class(type.to, input=True)
    return graphene.NonNull(get_class(type.to, input=True))