Skip to content

Hello world example not working #689

Closed
@ahujamoh

Description

@ahujamoh

Dear Contributors,

I was trying the graphql example given on the website: https://graphql.org/code/#python

I copied the code exactly.

import graphene
class Query(graphene.ObjectType):
  hello = graphene.String()

  def resolve_hello(self, args, context, info):
    return 'Hello world!'

schema = graphene.Schema(query=Query)
result = schema.execute('{ hello }')
print(result.data['hello'])

Also having installed graphene using pip(angular is name of my virtualenv)

> pip install graphene
Requirement already satisfied: graphene in /Users/mohit/virtualenvs/angular/lib/python2.7/site-packages
Requirement already satisfied: six<2,>=1.10.0 in /Users/mohit/virtualenvs/angular/lib/python2.7/site-packages (from graphene)
Requirement already satisfied: graphql-core<3,>=2.0 in /Users/mohit/virtualenvs/angular/lib/python2.7/site-packages (from graphene)
Requirement already satisfied: promise<3,>=2.1 in /Users/mohit/virtualenvs/angular/lib/python2.7/site-packages (from graphene)
Requirement already satisfied: graphql-relay<1,>=0.4.5 in /Users/mohit/virtualenvs/angular/lib/python2.7/site-packages (from graphene)
Requirement already satisfied: rx>=1.6.0 in /Users/mohit/virtualenvs/angular/lib/python2.7/site-packages (from graphql-core<3,>=2.0->graphene)
Requirement already satisfied: typing in /Users/mohit/virtualenvs/angular/lib/python2.7/site-packages (from promise<3,>=2.1->graphene)
(angular)

I tried running python hello.py, but got the following error.

> python hello.py
No handlers could be found for logger "graphql.execution.executor"
Traceback (most recent call last):
  File "/Users/mohit/virtualenvs/angular/lib/python2.7/site-packages/graphql/execution/executor.py", line 311, in resolve_or_error
    return executor.execute(resolve_fn, source, info, **args)
  File "/Users/mohit/virtualenvs/angular/lib/python2.7/site-packages/graphql/execution/executors/sync.py", line 7, in execute
    return fn(*args, **kwargs)
graphql.error.located_error.GraphQLLocatedError: resolve_hello() takes exactly 4 arguments (2 given)
None

May I know if I got mistaken at some place, or the instructions on the website are incomplete?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions