How to use Query method of graph Package

Best Keploy code snippet using graph.Query

azure-resource-graph-datasource.go

Source:azure-resource-graph-datasource.go Github

copy

Full Screen

...20// AzureResourceGraphDatasource calls the Azure Resource Graph API's21type AzureResourceGraphDatasource struct {22 proxy serviceProxy23}24// AzureResourceGraphQuery is the query request that is built from the saved values for25// from the UI26type AzureResourceGraphQuery struct {27 RefID string28 ResultFormat string29 URL string30 JSON json.RawMessage31 InterpolatedQuery string32 TimeRange backend.TimeRange33}34const argAPIVersion = "2021-06-01-preview"35const argQueryProviderName = "/providers/Microsoft.ResourceGraph/resources"36func (e *AzureResourceGraphDatasource) resourceRequest(rw http.ResponseWriter, req *http.Request, cli *http.Client) {37 e.proxy.Do(rw, req, cli)38}39// executeTimeSeriesQuery does the following:40// 1. builds the AzureMonitor url and querystring for each query41// 2. executes each query by calling the Azure Monitor API42// 3. parses the responses for each query into data frames43func (e *AzureResourceGraphDatasource) executeTimeSeriesQuery(ctx context.Context, originalQueries []backend.DataQuery, dsInfo datasourceInfo, client *http.Client, url string) (*backend.QueryDataResponse, error) {44 result := &backend.QueryDataResponse{45 Responses: map[string]backend.DataResponse{},46 }47 queries, err := e.buildQueries(originalQueries, dsInfo)48 if err != nil {49 return nil, err50 }51 for _, query := range queries {52 result.Responses[query.RefID] = e.executeQuery(ctx, query, dsInfo, client, url)53 }54 return result, nil55}56func (e *AzureResourceGraphDatasource) buildQueries(queries []backend.DataQuery, dsInfo datasourceInfo) ([]*AzureResourceGraphQuery, error) {57 var azureResourceGraphQueries []*AzureResourceGraphQuery58 for _, query := range queries {59 queryJSONModel := argJSONQuery{}60 err := json.Unmarshal(query.JSON, &queryJSONModel)61 if err != nil {62 return nil, fmt.Errorf("failed to decode the Azure Resource Graph query object from JSON: %w", err)63 }64 azureResourceGraphTarget := queryJSONModel.AzureResourceGraph65 azlog.Debug("AzureResourceGraph", "target", azureResourceGraphTarget)66 resultFormat := azureResourceGraphTarget.ResultFormat67 if resultFormat == "" {68 resultFormat = "table"69 }70 interpolatedQuery, err := KqlInterpolate(query, dsInfo, azureResourceGraphTarget.Query)71 if err != nil {72 return nil, err73 }74 azureResourceGraphQueries = append(azureResourceGraphQueries, &AzureResourceGraphQuery{75 RefID: query.RefID,76 ResultFormat: resultFormat,77 JSON: query.JSON,78 InterpolatedQuery: interpolatedQuery,79 TimeRange: query.TimeRange,80 })81 }82 return azureResourceGraphQueries, nil83}84func (e *AzureResourceGraphDatasource) executeQuery(ctx context.Context, query *AzureResourceGraphQuery, dsInfo datasourceInfo, client *http.Client, dsURL string) backend.DataResponse {85 dataResponse := backend.DataResponse{}86 params := url.Values{}87 params.Add("api-version", argAPIVersion)88 dataResponseErrorWithExecuted := func(err error) backend.DataResponse {89 dataResponse = backend.DataResponse{Error: err}90 frames := data.Frames{91 &data.Frame{92 RefID: query.RefID,93 Meta: &data.FrameMeta{94 ExecutedQueryString: query.InterpolatedQuery,95 },96 },97 }98 dataResponse.Frames = frames99 return dataResponse100 }101 model, err := simplejson.NewJson(query.JSON)102 if err != nil {103 dataResponse.Error = err104 return dataResponse105 }106 reqBody, err := json.Marshal(map[string]interface{}{107 "subscriptions": model.Get("subscriptions").MustStringArray(),108 "query": query.InterpolatedQuery,109 "options": map[string]string{"resultFormat": "table"},110 })111 if err != nil {112 dataResponse.Error = err113 return dataResponse114 }115 req, err := e.createRequest(ctx, dsInfo, reqBody, dsURL)116 if err != nil {117 dataResponse.Error = err118 return dataResponse119 }120 req.URL.Path = path.Join(req.URL.Path, argQueryProviderName)121 req.URL.RawQuery = params.Encode()122 span, ctx := opentracing.StartSpanFromContext(ctx, "azure resource graph query")123 span.SetTag("interpolated_query", query.InterpolatedQuery)124 span.SetTag("from", query.TimeRange.From.UnixNano()/int64(time.Millisecond))125 span.SetTag("until", query.TimeRange.To.UnixNano()/int64(time.Millisecond))126 span.SetTag("datasource_id", dsInfo.DatasourceID)127 span.SetTag("org_id", dsInfo.OrgID)128 defer span.Finish()129 if err := opentracing.GlobalTracer().Inject(130 span.Context(),131 opentracing.HTTPHeaders,132 opentracing.HTTPHeadersCarrier(req.Header)); err != nil {133 return dataResponseErrorWithExecuted(err)134 }135 azlog.Debug("AzureResourceGraph", "Request ApiURL", req.URL.String())136 res, err := ctxhttp.Do(ctx, client, req)137 if err != nil {138 return dataResponseErrorWithExecuted(err)139 }140 argResponse, err := e.unmarshalResponse(res)141 if err != nil {142 return dataResponseErrorWithExecuted(err)143 }144 frame, err := ResponseTableToFrame(&argResponse.Data)145 if err != nil {146 return dataResponseErrorWithExecuted(err)147 }148 azurePortalUrl, err := getAzurePortalUrl(dsInfo.Cloud)149 if err != nil {150 return dataResponseErrorWithExecuted(err)151 }152 url := azurePortalUrl + "/#blade/HubsExtension/ArgQueryBlade/query/" + url.PathEscape(query.InterpolatedQuery)153 frameWithLink := addConfigData(*frame, url)154 if frameWithLink.Meta == nil {155 frameWithLink.Meta = &data.FrameMeta{}156 }157 frameWithLink.Meta.ExecutedQueryString = req.URL.RawQuery158 dataResponse.Frames = data.Frames{&frameWithLink}159 return dataResponse160}161func addConfigData(frame data.Frame, dl string) data.Frame {162 for i := range frame.Fields {163 if frame.Fields[i].Config == nil {164 frame.Fields[i].Config = &data.FieldConfig{}165 }166 deepLink := data.DataLink{167 Title: "View in Azure Portal",168 TargetBlank: true,169 URL: dl,170 }171 frame.Fields[i].Config.Links = append(frame.Fields[i].Config.Links, deepLink)...

Full Screen

Full Screen

schema.resolvers.go

Source:schema.resolvers.go Github

copy

Full Screen

...33 pageLimit := 2034 var count int6435 var moviesGraph []*model.Movie36 var movies []models.Movie37 // Query to get the count38 database.DB.Find(&movies, "title LIKE ? AND genre LIKE ? AND director LIKE ? AND producer LIKE ?", "%"+*title+"%", "%"+*genre+"%", "%"+*director+"%", "%"+*producer+"%").Count(&count)39 // Query to get the results40 database.DB.Limit(pageLimit).Offset((*page-1)*pageLimit).Preload("Actors").Find(&movies, "title LIKE ? AND genre LIKE ? AND director LIKE ? AND producer LIKE ?", "%"+*title+"%", "%"+*genre+"%", "%"+*director+"%", "%"+*producer+"%")41 for _, movie := range movies {42 actorsGraph := nestedActors(movie)43 movie := movieAssembler(movie)44 movie.Actors = actorsGraph45 moviesGraph = append(moviesGraph, &movie)46 }47 info := generateInfo(page, count, pageLimit)48 return &model.Movies{49 Info: &info,50 Data: moviesGraph,51 }, nil52}53func (r *queryResolver) Actor(ctx context.Context, id string) (*model.Actor, error) {54 var actorGraph model.Actor55 var actor models.Actor56 database.DB.Preload("Movies").Find(&actor, "id = ?", id)57 moviesGraph := nestedMovies(actor)58 actorGraph = actorAssembler(actor)59 actorGraph.Movies = moviesGraph60 return &actorGraph, nil61}62func (r *queryResolver) ActorsByIds(ctx context.Context, ids []string) ([]*model.Actor, error) {63 var actorsGraph []*model.Actor64 for _, id := range ids {65 var actor models.Actor66 database.DB.Preload("Movies").Find(&actor, "id = ?", id)67 moviesGraph := nestedMovies(actor)68 actorGraph := actorAssembler(actor)69 actorGraph.Movies = moviesGraph70 actorsGraph = append(actorsGraph, &actorGraph)71 }72 return actorsGraph, nil73}74func (r *queryResolver) Actors(ctx context.Context, page *int, name *string, gender *string) (*model.Actors, error) {75 pageLimit := 2076 var count int6477 var actorsGraph []*model.Actor78 var actors []models.Actor79 // Query to get the count80 database.DB.Find(&actors, "name LIKE ? AND gender ILIKE ?", "%"+*name+"%", *gender+"%").Count(&count)81 // Query to get the results82 database.DB.Limit(pageLimit).Offset((*page-1)*pageLimit).Preload("Movies").Find(&actors, "name LIKE ? AND gender ILIKE ?", "%"+*name+"%", *gender+"%")83 for _, actor := range actors {84 moviesGraph := nestedMovies(actor)85 actor := actorAssembler(actor)86 actor.Movies = moviesGraph87 actorsGraph = append(actorsGraph, &actor)88 }89 info := generateInfo(page, count, pageLimit)90 return &model.Actors{91 Info: &info,92 Data: actorsGraph,93 }, nil94}95// Query returns generated.QueryResolver implementation.96func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} }97type queryResolver struct{ *Resolver }...

Full Screen

Full Screen

grapqhl_test.go

Source:grapqhl_test.go Github

copy

Full Screen

...17)18type GraphQlTestSuite struct {19 DbBasedTestSuite20}21func ExecuteQuery(db *gorm.DB, query string) *GraphQlContrib.Result {22 schema, err := GraphQlContrib.NewSchema(23 GraphQlContrib.SchemaConfig{24 Query: graphql.Query(db),25 Mutation: mutation.Mutation(db),26 },27 )28 if err != nil {29 panic(err)30 }31 result := GraphQlContrib.Do(GraphQlContrib.Params{32 Schema: schema,33 RequestString: query,34 })35 return result36}37type TestingLoop struct {38 Query string39 Results string40}41// Testing the DB connection.42func (suite *GraphQlTestSuite) TestQuery() {43 content, _ := ioutil.ReadFile("./dummy_json.json")44 text := string(content)45 payload, _ := mutation.JsonStringParse(text)46 mutation.MigrateProcessedObject(payload, suite.DB)47 queries := map[int]TestingLoop{48 0: TestingLoop{49 Query: `query { funds { fund_name } }`,50 Results: "{\"data\":{\"funds\":[{\"fund_name\":\"מקפת מרכז\"}]}}\n",51 },52 1: TestingLoop{53 Query: `query { instrument(id:1) { instrument_name } }`,54 Results: "{\"data\":{\"instrument\":{\"instrument_name\":\"בנק הפועלים בע\\\"מ\"}}}\n",55 },56 }57 e := echo.New()58 h := echo.WrapHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {59 b, err := ioutil.ReadAll(r.Body)60 if err != nil {61 panic(err)62 }63 results := ExecuteQuery(suite.DB, fmt.Sprintf("%s", b))64 json.NewEncoder(w).Encode(results)65 }))66 for _, testingLoop := range queries {67 req := httptest.NewRequest(http.MethodPost, "/graphql", strings.NewReader(testingLoop.Query))68 rec := httptest.NewRecorder()69 c := e.NewContext(req, rec)70 if assert.NoError(suite.T(), h(c)) {71 assert.Equal(suite.T(), http.StatusOK, rec.Code)72 assert.Equal(suite.T(), testingLoop.Results, rec.Body.String())73 }74 }75}76func (suite *GraphQlTestSuite) TestMutation() {77 // todo.78}79func TestGraphQl(t *testing.T) {80 suite.Run(t, new(GraphQlTestSuite))81}...

Full Screen

Full Screen

Query

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 g := graph.New(4)4 g.Add(0, 1)5 g.Add(0, 2)6 g.Add(1, 2)7 g.Add(2, 0)8 g.Add(2, 3)9 g.Add(3, 3)10}11import (12func main() {13 g := graph.New(4)14 g.Add(0, 1)15 g.Add(0, 2)16 g.Add(1, 2)17 g.Add(2, 0)18 g.Add(2, 3)19 g.Add(3, 3)20}

Full Screen

Full Screen

Query

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 g := graph.New(5)4 g.Add(0, 1)5 g.Add(0, 2)6 g.Add(1, 3)7 g.Add(2, 3)8 g.Add(3, 4)9 g.Add(4, 0)10 fmt.Println(g.Query(0, 2))11 fmt.Println(g.Query(2, 0))12 fmt.Println(g.Query(0, 3))13 fmt.Println(g.Query(3, 0))14 fmt.Println(g.Query(0, 4))15 fmt.Println(g.Query(4, 0))16}17import (18func main() {19 g := graph.New(5)20 g.Add(0, 1)21 g.Add(0, 2)22 g.Add(1, 3)23 g.Add(2, 3)24 g.Add(3, 4)25 g.Add(4, 0)26 fmt.Println(g.Query(0, 2))27 fmt.Println(g.Query(2, 0))28 fmt.Println(g.Query(0, 3))29 fmt.Println(g.Query(3, 0))30 fmt.Println(g.Query(0, 4))31 fmt.Println(g.Query(4, 0))32}33import (34func main() {35 g := graph.New(5)36 g.Add(0, 1)37 g.Add(0, 2)38 g.Add(1, 3)39 g.Add(2, 3)40 g.Add(3, 4)41 g.Add(4, 0)42 fmt.Println(g.Query(0, 2))43 fmt.Println(g.Query(2, 0))44 fmt.Println(g.Query(0, 3))45 fmt.Println(g.Query(3, 0))46 fmt.Println(g.Query(0, 4))47 fmt.Println(g.Query(4, 0))48}

Full Screen

Full Screen

Query

Using AI Code Generation

copy

Full Screen

1func main() {2 g := graph.NewGraph()3 g.AddEdge(1, 2)4 g.AddEdge(2, 3)5 g.AddEdge(2, 4)6 g.AddEdge(3, 4)7 g.AddEdge(4, 5)8 g.AddEdge(5, 6)9 g.AddEdge(5, 7)10 g.AddEdge(6, 7)11 g.AddEdge(7, 8)12 g.AddEdge(8, 9)13 g.AddEdge(8, 10)14 g.AddEdge(9, 10)15 g.AddEdge(10, 11)16 g.AddEdge(11, 12)17 g.AddEdge(11, 13)18 g.AddEdge(12, 13)19 g.AddEdge(13, 14)20 g.AddEdge(14, 15)21 g.AddEdge(14, 16)22 g.AddEdge(15, 16)23 g.AddEdge(16, 17)24 g.AddEdge(17, 18)25 g.AddEdge(17, 19)26 g.AddEdge(18, 19)27 g.AddEdge(19, 20)28 g.AddEdge(20, 21)29 g.AddEdge(20, 22)30 g.AddEdge(21, 22)31 g.AddEdge(22, 23)32 g.AddEdge(23, 24)33 g.AddEdge(23, 25)34 g.AddEdge(24, 25)35 g.AddEdge(25, 26)36 g.AddEdge(26, 27)37 g.AddEdge(26, 28)38 g.AddEdge(27, 28)39 g.AddEdge(28, 29)40 g.AddEdge(29, 30)41 g.AddEdge(29, 31)42 g.AddEdge(30, 31)43 g.AddEdge(31, 32)44 g.AddEdge(32, 33)45 g.AddEdge(32, 34)46 g.AddEdge(33, 34)47 g.AddEdge(34, 35)48 g.AddEdge(35, 36)49 g.AddEdge(35, 37)50 g.AddEdge(36, 37)51 g.AddEdge(37,

Full Screen

Full Screen

Query

Using AI Code Generation

copy

Full Screen

1func main() {2 graph := graph.NewGraph()3 graph.AddEdge("A", "B")4 graph.AddEdge("B", "C")5 graph.AddEdge("C", "D")6 graph.AddEdge("D", "E")7 graph.AddEdge("E", "F")8 graph.AddEdge("F", "G")9 graph.AddEdge("G", "H")10 graph.AddEdge("H", "I")11 graph.AddEdge("I", "J")12 graph.AddEdge("J", "K")13 graph.AddEdge("K", "L")14 graph.AddEdge("L", "M")15 graph.AddEdge("M", "N")16 graph.AddEdge("N", "O")17 graph.AddEdge("O", "P")18 graph.AddEdge("P", "Q")19 graph.AddEdge("Q", "R")20 graph.AddEdge("R", "S")21 graph.AddEdge("S", "T")22 graph.AddEdge("T", "U")23 graph.AddEdge("U", "V")24 graph.AddEdge("V", "W")25 graph.AddEdge("W", "X")26 graph.AddEdge("X", "Y")27 graph.AddEdge("Y", "Z")28 graph.AddEdge("Z", "A")29 graph.AddEdge("A", "C")30 graph.AddEdge("C", "E")31 graph.AddEdge("E", "G")32 graph.AddEdge("G", "I")33 graph.AddEdge("I", "K")34 graph.AddEdge("K", "M")35 graph.AddEdge("M", "O")36 graph.AddEdge("O", "Q")37 graph.AddEdge("Q", "S")38 graph.AddEdge("S", "U")39 graph.AddEdge("U", "W")40 graph.AddEdge("W", "Y")41 graph.AddEdge("Y", "B")42 graph.AddEdge("B", "D")43 graph.AddEdge("D", "F")44 graph.AddEdge("F", "H")45 graph.AddEdge("H", "J")46 graph.AddEdge("J", "L")47 graph.AddEdge("L", "N")48 graph.AddEdge("N", "P")49 graph.AddEdge("P", "R")50 graph.AddEdge("R", "T")51 graph.AddEdge("T",

Full Screen

Full Screen

Query

Using AI Code Generation

copy

Full Screen

1func main() {2 g := NewGraph(4)3 g.AddEdge(0, 1)4 g.AddEdge(0, 2)5 g.AddEdge(1, 2)6 g.AddEdge(2, 0)7 g.AddEdge(2, 3)8 g.AddEdge(3, 3)9 fmt.Println("Following is Breadth First Traversal (starting from vertex", s, ")")10 g.Query(s, d)11}

Full Screen

Full Screen

Query

Using AI Code Generation

copy

Full Screen

1import (2func main() {3}4import (5type Graph struct {6}7type Node struct {8}9type Edge struct {10}11func (e Edge) String() string {12 return fmt.Sprintf("%s -> %s (%f)", e.from.name, e.to.name, e.cost)13}14type Path struct {15}16func (p Path) String() string {17 for _, e := range p.edges {18 str += e.String() + "19 }20}21func NewGraph() *Graph {22 return &Graph{nodes: make(map[string]*Node)}23}24func (g *Graph) AddNode(name string) {25 g.nodes[name] = &Node{name: name, edges: make(map[string]*Edge)}26}27func (g *Graph) AddEdge(from, to string, cost float64) {28 if !ok {29 f = &Node{name: from, edges: make(map[string]*Edge)}30 }31 if !ok {32 t = &Node{name: to, edges: make(map[string]*Edge)}33 }34 f.edges[to] = &Edge{from: f, to: t, cost: cost}35}36func (g *Graph) Query(from, to string) Path {37 if !ok {38 return Path{}39 }40 if !ok {41 return Path{}42 }43 q := &priorityQueue{}44 heap.Init(q)45 heap.Push(q, &item{node: f, cost: 0.0})46 visited := make(map[*Node]*Path)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful