Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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}}
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)
'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
)
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
)
'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
)
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
)
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)
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)
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
}
}
}
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}))