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

Querying on "article" on blog endpoint fails. #7

Open
jamesroseman opened this issue Jan 25, 2016 · 1 comment
Open

Querying on "article" on blog endpoint fails. #7

jamesroseman opened this issue Jan 25, 2016 · 1 comment

Comments

@jamesroseman
Copy link
Contributor

{
  article {
    author {
      name
    },
    body
  }
}

http://localhost:4000/graphql/blog?query=%7B%0A%09article%20%7B%0A%09%20%20id%0A%09%7D%0A%7D

Hitting this endpoint results in this error message on iQL:

SyntaxError: Unexpected token <

And this error message in console:

[error] #PID<0.433.0> running HelloGraphQL.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /graphql/blog
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in anonymous fn/3 in GraphQL.Schema.SimpleBlog.schema/0
        (hello_graphql) web/graphql/simple_blog_schema.ex:58: anonymous fn(%{}, %{}, %{field_asts: [%{kind: :Field, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "article"}, selectionSet: %{kind: :SelectionSet, loc: %{start: 0}, selections: [%{kind: :Field, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "author"}, selectionSet: %{kind: :SelectionSet, loc: %{start: 0}, selections: [%{kind: :Field, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "id"}}]}}, %{kind: :Field, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "body"}}, %{kind: :Field, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "id"}}, %{kind: :Field, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "isPublished"}}]}}], field_name: :article, fragments: %{}, operation: %{kind: :OperationDefinition, loc: %{start: 0}, operation: :query, selectionSet: %{kind: :SelectionSet, loc: %{start: 0}, selections: [%{kind: :Field, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "article"}, selectionSet: %{kind: :SelectionSet, loc: %{start: 0}, selections: [%{kind: :Field, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "author"}, selectionSet: %{kind: :SelectionSet, loc: %{start: 0}, selections: [%{kind: :Field, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "id"}}]}}, %{kind: :Field, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "body"}}, %{kind: :Field, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "id"}}, %{kind: :Field, loc: %{start: 0}, name: %{kind: :Name, loc: %{start: 0}, value: "isPublished"}}]}}]}}, parent_type: %GraphQL.Type.ObjectType{description: "", fields: %{article: %{args: %{id: %{type: %GraphQL.Type.ID{description: "The `ID` scalar type represents a unique identifier, often used to\nrefetch an object or as key for a cache. The ID type appears in a JSON\nresponse as a String; however, it is not intended to be human-readable.\nWhen expected as an input type, any string (such as `\"4\"`) or integer\n(such as `4`) input value will be accepted as an ID.\n", name: "ID"}}}, resolve: #Function<1.131101731/3 in GraphQL.Schema.SimpleBlog.schema/0>, type: %GraphQL.Type.ObjectType{description: "A blog post", fields: %{author: %{type: %GraphQL.Type.ObjectType{description: "Author of the blog, with their profile picture and latest article", fields: %{id: %{type: %GraphQL.Type.String{description: "The `String` scalar type represents textual data, represented as UTF-8\ncharacter sequences. The String type is most often used by GraphQL to\nrepresent free-form human-readable text.\n", name: "String"}}, name: %{type: %GraphQL.Type.String{description: "The `String` scalar type represents textual data, represented as UTF-8\ncharacter sequences. The String type is most often used by GraphQL to\nrepresent free-form human-readable text.\n", name: "String"}}, pic: %{args: %{height: %{type: %GraphQL.Type.Int{description: "The `Int` scalar type represents non-fractional signed whole numeric\nvalues. Int can represent values between -(2^53 - 1) and 2^53 - 1 since\nrepresented in JSON as double-precision floating point numbers specified\nby [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).\n", name: "Int"}}, width: %{type: %GraphQL.Type.Int{description: "The `Int` scalar type represents non-fractional signed whole numeric\nvalues. Int can represent values between -(2^53 - 1) and 2^53 - 1 since\nrepresented in JSON as double-precision floating point numbers specified\nby [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).\n", name: "Int"}}}, resolve: #Function<0.131101731/3 in GraphQL.Schema.SimpleBlog.schema/0>, type: %GraphQL.Type.ObjectType{description: "Images for an article or a profile picture", fields: %{height: %{type: %GraphQL.Type.Int{description: "The `Int` scalar type represents non-fractional signed whole numeric\nvalues. Int can represent values between -(2^53 - 1) and 2^53 - 1 since\nrepresented in JSON as double-precision floating point numbers specified\nby [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).\n", name: "Int"}}, url: %{type: %GraphQL.Type.String{description: "The `String` scalar type represents textual data, represented as UTF-8\ncharacter sequences. The String type is most often used by GraphQL to\nrepresent free-form human-readable text.\n", name: "String"}}, width: %{type: %GraphQL.Type.Int{description: "The `Int` scalar type represents non-fractional signed whole numeric\nvalues. Int can represent values between -(2^53 - 1) and 2^53 - 1 since\nrepresented in JSON as double-precision floating point numbers specified\nby [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).\n", name: "Int"}}}, interfaces: [], name: "Image"}}}, interfaces: [], name: "Author"}}, body: %{type: %GraphQL.Type.String{description: "The `String` scalar type represents textual data, represented as UTF-8\ncharacter sequences. The String type is most often used by GraphQL to\nrepresent free-form human-readable text.\n", name: "String"}}, id: %{type: %GraphQL.Type.NonNull{ofType: %GraphQL.Type.String{description: "The `String` scalar type represents textual data, represented as UTF-8\ncharacter sequences. The String type is most often used by GraphQL to\nrepresent free-form human-readable text.\n", name: "String"}}}, isPublished: %{type: %GraphQL.Type.Boolean{description: "The `Boolean` scalar type represents `true` or `false`.\n", name: "Boolean"}}, keywords: %{type: %GraphQL.Type.List{ofType: %GraphQL.Type.String{description: "The `String` scalar type represents textual data, represented as UTF-8\ncharacter sequences. The String type is most often used by GraphQL to\nrepresent free-form human-readable text.\n", name: "String"}}}, title: %{type: %GraphQL.Type.String{description: "The `String` scalar type represents textual data, represented as UTF-8\ncharacter sequences. The String type is most often used by GraphQL to\nrepresent free-form human-readable text.\n", name: "String"}}}, interfaces: [], name: "Article"}}, feed: %{resolve: #Function<2.131101731/3 in GraphQL.Schema.SimpleBlog.schema/0>, type: %GraphQL.Type.List{ofType: %GraphQL.Type.ObjectType{description: "A blog post", fields: %{author: %{type: %GraphQL.Type.ObjectType{description: "Author of the blog, with their profile picture and latest article", fields: %{id: %{type: %GraphQL.Type.String{description: "The `String` scalar type represents textual data, represented as UTF-8\ncharacter sequences. The String type is most often used by GraphQL to\nrepresent free-form human-readable text.\n", name: "String"}}, name: %{type: %GraphQL.Type.String{description: "The `String` scalar type represents textual data, represented as UTF-8\ncharacter sequences. The String type is most often used by GraphQL to\nrepresent free-form human-readable text.\n", name: "String"}}, pic: %{args: %{height: %{type: %GraphQL.Type.Int{description: "The `Int` scalar type represents non-fractional signed whole numeric\nvalues. Int can represent values between -(2^53 - 1) and 2^53 - 1 since\nrepresented in JSON as double-precision floating point numbers specified\nby [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).\n", name: "Int"}}, width: %{type: %GraphQL.Type.Int{description: "The `Int` scalar type represents non-fractional signed whole numeric\nvalues. Int can represent values between -(2^53 - 1) and 2^53 - 1 since\nrepresented in JSON as double-precision floating point numbers specified\nby [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).\n", name: "Int"}}}, resolve: #Function<0.131101731/3 in GraphQL.Schema.SimpleBlog.schema/0>, type: %GraphQL.Type.ObjectType{description: "Images for an article or a profile picture", fields: %{height: %{type: %GraphQL.Type.Int{descr (truncated)

I'm unsure if article querying is allowed across all objects (rather than just by id), and it's broken, or that's just strictly not allowed behavior. I'm new to Phoenix/Elixir, so I'm not positive -- reporting just to be sure you're aware.

@jamesroseman
Copy link
Contributor Author

I see now what's going on. I think the functionality I'm looking for is defined as feed rather than something like article without ID argument, or even articles. I understand this whole project is a mock to demonstrate how easily the GraphQL plug works, but for newbies it's difficult to understand why there's no supported functionality for a general article query that returns all articles.

In simple_blog_schema.ex:

%Schema{query: blog_query}

...where a blog_query is:

blog_query = %ObjectType{
      name: "Query",
      fields: %{
        article: %{
          type: article,
          args: %{id: %{type: %ID{}}},
          resolve: fn(_, %{id: id}, _) -> make_article(id) end
        },
        feed: %{
          type: %List{ofType: article},
          resolve: fn(_, _, _) -> for id <- 1..2, do: make_article(id) end
        }
      }
    }

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

1 participant