Exploring the Code

Explore the query and codes to understand how StepZen works

Explore the Code

Let's take a quick look at the code to better understand how StepZen works. The schema is currently made up of two files:

  • weather-report-owm.graphql
  • index.graphql

/openweathermap/weather-report-owm.graphql

This file contains the schema type (WeatherReport) and query (WeatherReport) that we saw in the query editor example in the Getting Started Overview.

The WeatherReport type defines different 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. The Query type has only one query weatherReport which accepts the following arguments:

  • longitude
  • latitude

The result returns a weatherReport object.

The @connector code is a custom StepZen Graphql directive that tells StepZen to use our built-in OpenWeatherMap connector. We'll dig more into the StepZen's custom directives in a later tutorial.

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"
    )
}

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

index.graphql

This file is essentially the glue that pulls together all the other .graphql files in your schema. We currently only have one other file, so this is the only one that it lists.

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

As we add additional .graphql files with more types and queries, we'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. Technically, this isn't a requirement for a StepZen schema. Rather, it is a file written out by the StepZen CLI to store settings and configuration.

Remember earlier when the CLI asked us what we want to name our API? This is where that information was ultimately stored.

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.