11import React , { useState , useMemo } from "react" ;
22import { VStack , HStack , Button , Textarea , Text , Box } from "@chakra-ui/react" ;
33import { Play } from "lucide-react" ;
4- import { useObjectsQuery } from "@trustgraph/react-state" ;
4+ import { useRowsQuery } from "@trustgraph/react-state" ;
55import {
66 createColumnHelper ,
77 useReactTable ,
@@ -17,12 +17,12 @@ const columnHelper = createColumnHelper<GraphQLResultRow>();
1717
1818const RunGraphQLTab : React . FC = ( ) => {
1919 const [ query , setQuery ] = useState ( "" ) ;
20- const objectsQuery = useObjectsQuery ( ) ;
20+ const rowsQuery = useRowsQuery ( ) ;
2121
2222 const handleSubmit = ( ) => {
2323 if ( ! query . trim ( ) ) return ;
2424
25- objectsQuery . executeQuery ( { query : query . trim ( ) } ) ;
25+ rowsQuery . executeQuery ( { query : query . trim ( ) } ) ;
2626 } ;
2727
2828 const handleKeyPress = ( e : React . KeyboardEvent ) => {
@@ -34,20 +34,20 @@ const RunGraphQLTab: React.FC = () => {
3434
3535 // Dynamically create columns based on the first row of results
3636 const { columns, tableData } = useMemo ( ( ) => {
37- if ( ! objectsQuery . data ?. data ) {
37+ if ( ! rowsQuery . data ?. data ) {
3838 return { columns : [ ] , tableData : [ ] } ;
3939 }
4040
4141 // Extract the first array of results from the GraphQL response
4242 // GraphQL responses typically have structure like { data: { users: [...] } }
43- const dataKeys = Object . keys ( objectsQuery . data . data ) ;
43+ const dataKeys = Object . keys ( rowsQuery . data . data ) ;
4444 if ( dataKeys . length === 0 ) {
4545 return { columns : [ ] , tableData : [ ] } ;
4646 }
4747
4848 // Get the first data collection
4949 const firstKey = dataKeys [ 0 ] ;
50- const results = objectsQuery . data . data [ firstKey ] ;
50+ const results = rowsQuery . data . data [ firstKey ] ;
5151
5252 if ( ! Array . isArray ( results ) || results . length === 0 ) {
5353 return { columns : [ ] , tableData : [ ] } ;
@@ -91,7 +91,7 @@ const RunGraphQLTab: React.FC = () => {
9191 columns : resultColumns ,
9292 tableData : results as GraphQLResultRow [ ] ,
9393 } ;
94- } , [ objectsQuery . data ] ) ;
94+ } , [ rowsQuery . data ] ) ;
9595
9696 // Create the table instance
9797 const table = useReactTable ( {
@@ -136,8 +136,8 @@ const RunGraphQLTab: React.FC = () => {
136136 onClick = { handleSubmit }
137137 disabled = {
138138 ! query . trim ( ) ||
139- objectsQuery . isExecuting ||
140- ! objectsQuery . isReady
139+ rowsQuery . isExecuting ||
140+ ! rowsQuery . isReady
141141 }
142142 colorPalette = "primary"
143143 >
@@ -148,13 +148,13 @@ const RunGraphQLTab: React.FC = () => {
148148 </ VStack >
149149
150150 { /* Error Display */ }
151- { objectsQuery . error && (
151+ { rowsQuery . error && (
152152 < Box >
153153 < Text fontWeight = "medium" fontSize = "lg" color = "red.500" mb = { 2 } >
154154 Query Error
155155 </ Text >
156156 < Textarea
157- value = { `Error: ${ objectsQuery . error . message || objectsQuery . error } ` }
157+ value = { `Error: ${ rowsQuery . error . message || rowsQuery . error } ` }
158158 readOnly
159159 rows = { 4 }
160160 bg = "red.50"
@@ -167,13 +167,13 @@ const RunGraphQLTab: React.FC = () => {
167167 ) }
168168
169169 { /* GraphQL Errors Display */ }
170- { objectsQuery . data ?. errors && objectsQuery . data . errors . length > 0 && (
170+ { rowsQuery . data ?. errors && rowsQuery . data . errors . length > 0 && (
171171 < Box >
172172 < Text fontWeight = "medium" fontSize = "lg" color = "orange.500" mb = { 2 } >
173173 GraphQL Errors
174174 </ Text >
175175 < Textarea
176- value = { objectsQuery . data . errors
176+ value = { rowsQuery . data . errors
177177 . map (
178178 ( error : Record < string , unknown > ) =>
179179 ( error . message as string ) || JSON . stringify ( error ) ,
@@ -191,7 +191,7 @@ const RunGraphQLTab: React.FC = () => {
191191 ) }
192192
193193 { /* Results Table */ }
194- { objectsQuery . data ?. data && tableData . length > 0 && (
194+ { rowsQuery . data ?. data && tableData . length > 0 && (
195195 < VStack gap = { 4 } align = "stretch" >
196196 < HStack justify = "space-between" align = "center" >
197197 < Text fontWeight = "medium" fontSize = "lg" >
@@ -209,9 +209,9 @@ const RunGraphQLTab: React.FC = () => {
209209 ) }
210210
211211 { /* No Results Message */ }
212- { objectsQuery . data ?. data &&
212+ { rowsQuery . data ?. data &&
213213 tableData . length === 0 &&
214- ! objectsQuery . error && (
214+ ! rowsQuery . error && (
215215 < Box >
216216 < Text fontWeight = "medium" fontSize = "lg" mb = { 2 } >
217217 Query Results
0 commit comments