Giter VIP home page Giter VIP logo

Comments (3)

syrusakbary avatar syrusakbary commented on August 19, 2024 1

Hi @ustun,

I've fixed the name argument in Fields with this commit: 2eea03c

So the first code you wrote would work perfectly.

About the last code you wrote:

import graphene


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

    def resolve_hello(self, args, info):
        return 'Hello ' + args.get('first_name')

schema = graphene.Schema(query=Query)

result = schema.execute("""
query foo($first_name:String)
{
        hello(first_name:$first_name)
}
""", args={"first_name": "Serkan"})

print result.data

Graphene, converts (by default, could be disabled) not only the field names in ObjectTypes/Interfaces, but also the argument names to be camelCase when you query it.
So if you use an argument for having a first_name name, you should query in the GraphQL query using: firstName.
Like:

result = schema.execute("""
query foo($firstName:String)
{
        hello(firstName:$firstName)
}
""", args={"firstName": "Serkan"})

About the from error, it's a Python syntax error, so Graphene will not show any errors for that, as it will not be executed.

Hope it helps!

from graphene.

ustun avatar ustun commented on August 19, 2024

Also, possibly related, underscores in field names do not work:


import graphene


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

    def resolve_hello(self, args, info):
        return 'Hello ' + args.get('first_name')

schema = graphene.Schema(query=Query)

result = schema.execute("""
query foo($first_name:String)
{
        hello(first_name:$first_name)
}
""", args={"first_name": "Serkan"})

print result.data

from graphene.

ustun avatar ustun commented on August 19, 2024

Incidentally, from argument name was the first thing I tried on the playground since it accepts an argument named to and it took me some time to remember that from is a keyword. Maybe the error message could be made better there too.

http://graphene-python.org/playground/?schema=import%2520graphene%250A%250Aclass%2520Query(graphene.ObjectType)%253A%250A%2520%2520%2520%2520hello%2520%253D%2520graphene.String()%250A%2520%2520%2520%2520ping%2520%253D%2520graphene.String(to%253Dgraphene.String()%252C%2520from%253Dgraphene.String())%250A%250A%2520%2520%2520%2520def%2520resolve_hello(self%252C%2520args%252C%2520info)%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520return%2520%27World%27%250A%250A%2520%2520%2520%2520def%2520resolve_ping(self%252C%2520args%252C%2520info)%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520return%2520%27Pinging%2520%257B%257D%2520%257B%257D%27.format(args.get(%27to%27)%252C%2520args.get(%27from%27))%250A%250Aschema%2520%253D%2520graphene.Schema(query%253DQuery)%250A&query=query%2520%257B%250A%2520%2520hello%250A%2520%2520ping(to%253A%2522Peter%2522%252C%2520FROM%253A%2520%2522Ustun%2522)%250A%257D%250A

from graphene.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.