Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON result #1

Closed
zdnk opened this issue Oct 30, 2016 · 8 comments
Closed

JSON result #1

zdnk opened this issue Oct 30, 2016 · 8 comments

Comments

@zdnk
Copy link

zdnk commented Oct 30, 2016

Hi,

I am having trouble converting returned Map object to JSON. There seems to be no method to simply convert the result to simple dictionary convertible to JSON or any other obvious way.
Or at least simple string valid as HTTP response body.

@paulofaria
Copy link
Member

Hello! The Mapobject is like most JSON types are represented currently in Swiftland. To get a JSON string simply call description.

let result = try graphql(schema: StarWarsSchema, request: query)
print(result.description)

example output:

{
    "data": {
        "hero": {
            "name": "R2-D2"
        }
    }
}

In debug mode it will pretty print the JSON string. In release mode it will print a minified version.
If this is not enough let me know what you need. 😊

@paulofaria
Copy link
Member

Just so you know I released Graphiti. Which is a swiftier DSL to create your types/schemas.

@paulofaria
Copy link
Member

More news! Just released GraphQLResponder. It's a Zewo responder (kinda like a middleware) with GraphiQL support included. 😊

@paulofaria
Copy link
Member

ping!

@zdnk
Copy link
Author

zdnk commented Nov 1, 2016

For me it returns:

"{
    "data": {
        "hero": {
            "name": "R2-D2"
        }
    }
}"

In those " :(

@zdnk
Copy link
Author

zdnk commented Nov 1, 2016

Graphiti looks good, I am currently starting a new web project in Swift and deciding between Vapor and Zewo.

It would be awesome if Mapcould return simple Dictionary<String, Any> that is simply serializable to JSON.

@johndpope
Copy link

@zdenektopic - this might help https://github.com/utahiosmac/Marshal

@zdnk
Copy link
Author

zdnk commented Dec 13, 2016

I think it should support it out-of-box. I dont need mapping to object, I just need to get simple dictionary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants