For this introductory example I am going with a classic "Hello World!" program which just shows how to setup and initialize a basic API request. GraphQL does get more interesting and I will show more complex queries in later posts. The goal here is just to show how to get up and running with querying API's using GraphQL.
First I created a new directory using the CLI(command line interface) that I am connecting to via SSH from the terminal on my home work machine. Once I went through all the server setup and installations it was time to test out the system. For this I created a server.js file and added the contents seen below. Here a schema is defined with a query that will return a string with the value stored in '{ hello }' within var root. Then I pass the response and log it to the console in the terminal.
And the initial response from the first GraphQL query below confirms that string of data was successfully returned from my query.
Hello World! from GraphQL using Node.js |
No comments:
Post a Comment