GraphQL Cookbook
Getting an object
10 min
getting an object through the parse graphql api problem you want to get an existing object from your database through the parse graphql api solution using the parse graphql, there are two different ways to get an existing object from your database using generic query https //www back4app com/docs/parse graphql/graphql query get object#query generic this is the query that you can use to get an object of any class using class query https //www back4app com/docs/parse graphql/graphql query get object#query class this is the recommended query that you should use to get an object of a specific class version information depending on the version of parse you choose to run, the graphql queries, mutations and results will be slightly different please choose the correct example along with the parse version you are running using generic query when you use the get get generic query, parse server behaves like a schemaless database it means that you do not need to specify which object’s fields you want to get you just need to send the object’s classname classname and objectid objectid , and parse server will return all fields of this object therefore, the objects’ get get generic query is the query that you can use for getting an existing object of any class if you want to get an existing object of a specific class, we recommend using the class query https //www back4app com/docs/parse graphql/graphql query get object#query class this example will only work if you use a classname classname with existing object you can create an object using the creating an object recipe parse server 3 8 0 request 1 query getobject { 2 get(classname "hero", objectid "rr8jmfrnks") 3 } response 1 { 2 "data" { 3 "get" { 4 "objectid" "rr8jmfrnks", 5 "name" "luke skywalker", 6 "createdat" "2019 11 04t12 42 40 723z", 7 "updatedat" "2019 11 04t12 42 40 723z" 8 } 9 } 10 } example parse 3 9 0 and later parse 3 9 and later do not have the generic methods get and find you must use the specific methods below to retrieve objects using class query once you have already created your object’s class in your application’s schema (for instance, using the creating an object https //www back4app com/docs/parse graphql/graphql mutation create object#mutation generic recipe), parse server instantly adds to your graphql api a new get\<classname> get\<classname> query to get an existing object of this class therefore, the object’s class query is the recommended method for getting an existing object of a specific class since this query knows your class’ data, it will automatically make available for you additional features like code auto complete and validation this example will only work if you use a classname classname and an objectid objectid of an existing object you can create an object using the creating an object recipe parse server 3 10 0 and later request 1 query gethero { 2 hero(id "sgvybzpvrm5tvdm1ynbp") { 3 id, 4 name, 5 createdat, 6 updatedat 7 } 8 } response 1 { 2 "data" { 3 "hero" { 4 "id" "sgvybzpvrm5tvdm1ynbp", 5 "name" "r2 d2", 6 "createdat" "2020 02 06t13 13 26 678z", 7 "updatedat" "2020 02 06t13 13 26 678z" 8 } 9 } 10 } older parse server versions parse 3 9 0 class query request 1 query gethero { 2 hero(id "ckhurmmjzw") { 3 id, 4 name, 5 createdat, 6 updatedat 7 } 8 } response 1 { 2 "data" { 3 "hero" { 4 "id" "ckhurmmjzw", 5 "name" "luke skywalker", 6 "createdat" "2019 11 04t12 37 22 462z", 7 "updatedat" "2019 11 04t12 37 22 462z" 8 } 9 } 10 } parse server 3 8 0 class queryparse server 3 7 2 parse server 3 7 2 generic query request 1 query getobject { 2 objects { 3 get(classname "hero", objectid "ffyobotk85") 4 } 5 } response 1 { 2 "data" { 3 "objects" { 4 "get" { 5 "objectid" "ffyobotk85", 6 "name" "luke skywalker", 7 "createdat" "2019 07 15t01 25 20 875z", 8 "updatedat" "2019 07 15t01 25 20 875z" 9 } 10 } 11 } 12 } class query parse server 3 7 2 1 query gethero { 2 objects { 3 gethero(objectid "ffyobotk85") { 4 objectid, 5 name, 6 createdat, 7 updatedat 8 } 9 } 10 } result parse 3 7 2 1 { 2 "data" { 3 "objects" { 4 "gethero" { 5 "objectid" "ffyobotk85", 6 "name" "luke skywalker", 7 "createdat" "2019 07 15t01 25 20 875z", 8 "updatedat" "2019 07 15t01 25 20 875z" 9 } 10 } 11 } 12 }