Skip to content
This repository has been archived by the owner on May 21, 2022. It is now read-only.

added todo example #3

Closed
wants to merge 1 commit into from
Closed

added todo example #3

wants to merge 1 commit into from

Conversation

bsr203
Copy link

@bsr203 bsr203 commented Nov 4, 2015

No description provided.

@bsr203
Copy link
Author

bsr203 commented Nov 4, 2015

as mentioned here #1 , please see the todo example. It currently gives error for introspection query

{
  "error": {
    "message": "parser: malformed graphql operation: 1:1 (0): no match found"
  }
}

@tmc
Copy link
Owner

tmc commented Nov 4, 2015

@bsr203 thanks for this contribution, let's get this working. Which introspection query are you referring to?

@bsr203
Copy link
Author

bsr203 commented Nov 4, 2015

well, I just tested the existing example

e/basic_graphql_server ❯❯❯ go run main.go                                                                                                     master
2015/11/04 15:19:34 query: 
2015/11/04 15:19:34 error parsing: parser: malformed graphql operation: 1:1 (0): no match found
2015/11/04 15:19:36 query: 
2015/11/04 15:19:36 error parsing: parser: malformed graphql operation: 1:1 (0): no match found
2015/11/04 15:19:38 query: 
2015/11/04 15:19:38 error parsing: parser: malformed graphql operation: 1:1 (0): no match found
2015/11/04 15:19:48 query: 

which also gives the same error. I was using graphiql

may be please explain to me how do you test, basic_graphiql_example, I will get the introspection query in just bit

Edit:

for the todo app, the viewer query was failing

{"query":"query ViewerQueries{viewer{id,...__RelayQueryFragment0xh4pba}} fragment __RelayQueryFragment16p69yi on User{id,totalCount} fragment __RelayQueryFragment39q7490 on TodoConnection{edges{node{complete,id},cursor},pageInfo{hasNextPage,hasPreviousPage}} fragment __RelayQueryFragment4w5m15t on User{completedCount,id,totalCount} fragment __RelayQueryFragment2gl3aeh on User{completedCount,_todosa8fgf3:todos(status:\"completed\",first:9007199254740991){...__RelayQueryFragment39q7490},totalCount,id,...__RelayQueryFragment4w5m15t} fragment __RelayQueryFragment0xh4pba on User{totalCount,id,...__RelayQueryFragment16p69yi,...__RelayQueryFragment2gl3aeh}","variables":{}}

Will look further

@bsr203
Copy link
Author

bsr203 commented Nov 4, 2015

I was trying like

basic_graphql_server ❯❯❯ curl -XPOST -H "Content-Type:application/graphql"  -d 'query nowProvider { now }' http://localhost:8080            master
{"error":{"message":"parser: malformed graphql operation: 1:1 (0): no match found"}}

I am not sure about how the schema looks like, without seeing the json or graphiql. Can you please let me know how to run proper query in basic_graphql_server example. Also, is there a way to dump introspection query to use with relay

for example, this query fails

basic_graphql_server ❯❯❯ curl -XPOST  -d '{ __schema{ types {  name } } }'  http://localhost:8080                                           master
{"error":{"message":"parser: malformed graphql operation: 1:1 (0): no match found"}}

which works fine at http://goo.gl/6p6PdN

Edit:

found the correct query should have been

curl -sgG --data-urlencode "q={ __schema{ types { name } } }" http://localhost:8080/

from cgraphqli.sh script

and this works

 curl -sgG --data-urlencode "q={ now }" http://localhost:8080/                                                                       master
{
  "data": [
    "2015-11-04T16:16:06.51128663-05:00"
  ]
}%                                                   

still digging.

@bsr203
Copy link
Author

bsr203 commented Nov 4, 2015

Hi,
one issue of using with graphiql, etc that currently handler doesn't accept POST request. I saw from the doc that it is given as an example, so I may extend it. So, made some more progress by allowing POST request like

type Response struct {
    Query string `json:"query"`
}

//TODO(tmc): reject non-GET/OPTIONS requests
//TODO(bsr203) allow POST ?
func getQuery(r *http.Request) string {
    if r.Method != "POST" {
        q := r.URL.Query().Get("q")
        if q == "" {
            q = r.URL.Query().Get("query")
        }
        return q
    }
    body, err := ioutil.ReadAll(r.Body)
    if err != nil {
        panic(err) //TODO
    }
    var resp Response
    json.Unmarshal([]byte(body), &resp)
    return resp.Query
}

...

q := getQuery(r)
    log.Println("query:", q)

...

further, for the below introspection query from graphiql, I got error

2015/11/04 16:45:28 query: 
  query IntrospectionQuery {
    __schema {
      queryType { name }
      mutationType { name }
      types {
        ...FullType
      }
      directives {
        name
        description
        args {
          ...InputValue
        }
        onOperation
        onFragment
        onField
      }
    }
  }

  fragment FullType on __Type {
    kind
    name
    description
    fields {
      name
      description
      args {
        ...InputValue
      }
      type {
        ...TypeRef
      }
      isDeprecated
      deprecationReason
    }
    inputFields {
      ...InputValue
    }
    interfaces {
      ...TypeRef
    }
    enumValues {
      name
      description
      isDeprecated
      deprecationReason
    }
    possibleTypes {
      ...TypeRef
    }
  }

  fragment InputValue on __InputValue {
    name
    description
    type { ...TypeRef }
    defaultValue
  }

  fragment TypeRef on __Type {
    kind
    name
    ofType {
      kind
      name
      ofType {
        kind
        name
        ofType {
          kind
          name
        }
      }
    }
  }
error: {message: "No handler for field 'queryType' on type '*schema.Schema'"}

@bsr203
Copy link
Author

bsr203 commented Nov 5, 2015

@tmc I am not sure the implementation in this pull request is the best to follow. There are types defined for mutation, connection, ... and may unnecessary. I don't see all the root queries on viewer. Also, user has many fields (looks like all root fields).Invoking all the handlers through graph/schema also cause Graph type to explode

func (graph *Graph) GraphQLTypeInfo() schema.GraphQLTypeInfo {
+   return schema.GraphQLTypeInfo{
...
todo := graph.AddToDo(graph.Users["me"], input["text"].(string), false)
..
}

I would probably directly call my domain handlers from schema.

so, please treat it just an idea and anxious to see how you approach it.

Please give some pointers and I try to build on it.

Cheers.

@bsr203
Copy link
Author

bsr203 commented Nov 17, 2015

@tmc Hi Travis. Any time for this :-)

@bsr203 bsr203 closed this Aug 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants