Exemple #1
0
func TestStore(t *testing.T) {
	Convey("Verify map store can handle gra", t, func() {
		friends := []string{
			"james",
			"jen",
			"jill",
			"joe",
		}
		data := map[string]interface{}{
			"bill": map[string]interface{}{
				"friends": friends,
			},
		}
		store := New(data)

		buf := bytes.NewBuffer([]byte{})
		query := `query bill { friends }`
		err := graphql.New(store).Handle(query, buf)

		v := map[string]map[string][]string{}
		err = json.Unmarshal(buf.Bytes(), &v)
		So(err, ShouldBeNil)

		So(v, ShouldResemble, map[string]map[string][]string{
			"bill": map[string][]string{
				"friends": friends,
			},
		})
	})
}
Exemple #2
0
func ExampleGet() {
	query := `query city: GET("http://api.openweathermap.org/data/2.5/weather?q=London") {
		name
		weather: main {
			temperature: temp
		}
	}`

	store := restq.New()
	graphql.New(store).Handle(query, os.Stdout)
}
Exemple #3
0
func TestHelloWorld(t *testing.T) {
	Convey("Given the hello world query", t, func() {
		model := map[string]interface{}{"hello": "world"}
		store := mapq.New(model)
		buf := bytes.NewBuffer([]byte{})
		err := graphql.New(store).Handle(`{hello}`, buf)

		So(err, ShouldBeNil)
		So(buf.String(), ShouldEqual, `{"hello":"world"}`)
	})
}
func TestOpenWeatherMap(t *testing.T) {
	Convey("Given the rest graphql handler", t, func() {
		type Result struct {
			City struct {
				Name    string
				Weather struct {
					Temperature float32
				}
			}
		}

		query := `query city: GET(url:"http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139") {
			name
			weather: main {
				temperature: temp
			}
		}`

		buf := bytes.NewBuffer([]byte{})
		store := New()
		executor := graphql.New(store)

		So(query, ShouldNotBeNil)
		So(buf, ShouldNotBeNil)
		So(store, ShouldNotBeNil)
		So(executor, ShouldNotBeNil)

		//		err := executor.Handle(query, buf)
		//		So(err, ShouldBeNil)
		//
		//		result := Result{}
		//		err = json.Unmarshal(buf.Bytes(), &result)
		//		So(err, ShouldBeNil)
		//
		//		So(result.City.Name, ShouldEqual, "Shuzenji")
		//		So(result.City.Weather.Temperature, ShouldBeGreaterThan, 0.0)
	})
}
Exemple #5
0
func BenchmarkStore(b *testing.B) {
	friends := []string{
		"james",
		"jen",
		"jill",
		"joe",
	}
	data := map[string]interface{}{
		"bill": map[string]interface{}{
			"friends": friends,
		},
	}
	store := New(data)
	buf := bytes.NewBuffer(make([]byte, 16384))

	for i := 0; i < b.N; i++ {
		buf.Reset()
		query := `query bill { friends }`
		err := graphql.New(store).Handle(query, buf)
		if err != nil {
			log.Fatalln(err)
		}
	}
}
Exemple #6
0
func ExampleMap() {
	model := map[string]interface{}{"hello": "world"}
	store := mapq.New(model)
	graphql.New(store).Handle(`{hello}`, os.Stdout)
	// prints {"hello":"world"}
}