How to use the graphene.Schema function in graphene

To help you get started, we’ve selected a few graphene examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github joaovitorsilvestre / graphene-mongodb / tests / test_mongoschema.py View on Github external
def test_dict_field(self):
        class Post(Document):
            info = DictField()

        info = {
            "author": "João",
            "date": "2017-01-01"
        }

        Post(info=info).save()

        class PostSchema(MongraphSchema):
            __MODEL__ = Post

        Query = self.QueryBuilder([PostSchema])
        schema = graphene.Schema(query=Query)

        result = schema.execute(""" query testQuery {
            post {
                info
            }
        }""")

        assert result.data == {'post': {'info': info}}
github smbolton / howtographql-tutorial-graphene-backend / links / tests.py View on Github external
def test_node_for_viewer(self):
        query = '''
          query {
            viewer {
              id
            }
          }
        '''
        schema = graphene.Schema(query=Query)
        result = schema.execute(query)
        self.assertIsNone(result.errors, msg=format_graphql_errors(result.errors))
        viewer_gid = result.data['viewer']['id']
        query = '''
          query {
            node(id: "%s") {
              id
            }
          }
        ''' % viewer_gid
        expected = {
          'node': {
            'id': viewer_gid,
          }
        }
        result = schema.execute(query)
github barseghyanartur / graphene-elastic / examples / schema / user.py View on Github external
'pf_email': 'email.raw',
            'pf_created_at': 'created_at',
            'pf_is_active': 'is_active',
        }


class Query(graphene.ObjectType):
    """User query."""

    users = ElasticsearchConnectionField(
        User,
        enforce_first_or_last=True
    )


schema = graphene.Schema(
    query=Query
)
github graphql-python / swapi-graphene / starwars / schema.py View on Github external
assert _type == 'planet', 'The homeworld should be a Planet, but found {}'.format(resolved.type)
            except:
                raise Exception("Received wrong Planet id: {}".format(homeworld_id))

        homeworld = Planet._meta.model.objects.get(id=homeworld_id)
        hero = Hero._meta.model(name=name, homeworld=homeworld)
        hero.save()

        return CreateHero(hero=hero, ok=bool(hero.id))


class Mutation(graphene.ObjectType):
    create_hero = CreateHero.Field()


schema = graphene.Schema(
    query=Query,
    mutation=Mutation
)
github barseghyanartur / graphene-elastic / examples / schema / animal.py View on Github external
'default_lookup': LOOKUP_FILTER_TERM,
            },
            'app': {
                'field': 'app.raw',
                'default_lookup': LOOKUP_FILTER_TERM,
            },
        }


class Query(graphene.ObjectType):
    """Animal query."""

    animals = ElasticsearchConnectionField(Animal)


schema = graphene.Schema(
    query=Query
)
github ariannedee / graphql-django-presentation / django_site / goals / schema.py View on Github external
goal = graphene.Field(GoalNode)

    @atomic
    def mutate(self, args, context, info):
        kr = KeyResult.objects.get(pk=args['pk'])
        current_value = args['current_value']
        kr.current_value = current_value
        kr.save()
        return UpdateTask(goal=kr.objective)


class Mutation(graphene.ObjectType):
    create_goal = CreateGoal.Field(description='Create a new goal')
    updateTaskProgress = UpdateTask.Field()

schema = graphene.Schema(
    query=Query,
    mutation=Mutation
)
github SystangoTechnologies / DjangoUnboxed / boilerplate_app / graphql / schema.py View on Github external
filter_fields = {
            'project_name': ['exact', 'icontains', 'istartswith'],
            'user__email': ['exact']
        }
        interfaces = (relay.Node, )


class Query(ObjectType):
    user = relay.Node.Field(UserNode)
    all_users = DjangoFilterConnectionField(UserNode)

    project = relay.Node.Field(ProjectsNode)
    all_projects = DjangoFilterConnectionField(ProjectsNode)


schema = graphene.Schema(Query)
github jauhararifin / ugrade / server / ugrade / schema.py View on Github external
import graphene
import contests.schema


class Query(contests.schema.Query, graphene.ObjectType):
    pass


class Mutation(contests.schema.Mutation, graphene.ObjectType):
    pass


schema = graphene.Schema(query=Query, mutation=Mutation)
github joaovitorsilvestre / graphene-mongodb / examples / complex.py View on Github external
model = Country


class BankSchema(MongoSchema):
    model = Bank


class UserSchema(MongoSchema):
    model = User


class Query(graphene.ObjectType):
    user = UserSchema.single


schema = graphene.Schema(query=Query)

result = schema.execute("""query Data {
    user(username: "John") {
        id
        username
        active
        age
        score
        bank {
            name
            location
            country {
                name
                areaCode
            }
        }
github Droidtown / ArticutAPI / Toolkit / graphQL.py View on Github external
}
          numbers {
            text
            pos_
            tag_
          }
          sites {
            text
            pos_
            tag_
          }
        }
      }
    }"""):
        query = """{\n  nlp(filepath: "{{filePath}}", model: "TW") {{query}}\n}""".replace('{{filePath}}', filePath).replace('{{query}}', query)
        result = graphene.Schema(query=Query).execute(query)
        return json.loads(json.dumps({"data": result.data}))