Explore the Hello World Code

Explore the query and codes to understand how StepZen works

When you imported the pre-built GraphQL Schema for the Hello World example, this resulted in the creation of a StepZen project and the following directories/files on your local machine:

/hello-stepzen

  • /openweathermap
    • openweathermap.graphql
  • index.graphql
  • stepzen.config.json

Let's take a look at the project's files and the code in the schema files, to better understand how StepZen works.

The GraphQL schema files

The schema is defined by two files:

weather-report-owm.graphql

This file contains the schema type (weatherReport) and query (weatherReport) that you saw in the query editor example in Build your First Hello World API.

All of the types and queries that make up your StepZen schema will be contained in .graphql files like these.

The weatherReport type defines the fields that make up its data and the type of data it will contain (for example, Float, Date, String, etc.).

The query type defines the different queries available on the weatherReport type and the arguments that can be passed to them. MyQuery has only one query: weatherReport, which accepts the following arguments:

  • longitude
  • latitude

The result contains a weatherReport object.

Note: The @connector code is a custom StepZen Graphql directive that tells StepZen to use our built-in OpenWeatherMap connector:

type WeatherReport {
  date: Date!
  latitude: Float!
  longitude: Float!
  temp: Float
  feelsLike: Float
  description: String
  units: String
}

type Query {
  weatherReport(latitude: Float!, longitude: Float!): WeatherReport
    @connector(
      type: "__openweathermap_weather_location_connector__"
      configuration: "owm_default"
    )
}

index.graphql

This file is essentially the glue that pulls together all of the other .graphql files in your schema:

schema @sdl(
  files: [
    "openweathermap/weather-report-owm.graphql"
  ]
) {
  query: Query
}

As you add additional .graphql files with more types and queries, you'll need to add them to the list of files within index.graphql.

What about stepzen.config.json?

You may have noticed the stepzen.config.json file. This file is written out by the StepZen CLI to store settings like the name of an API, and isn't a requirement for a StepZen schema.

This site uses cookies: By using this website, you consent to our use of cookies in accordance with our Website Terms of Use and Cookie Policy.