Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load a directory which contains a list of SDL files #108

Closed
tsunammis opened this issue Jan 29, 2019 · 3 comments
Closed

Unable to load a directory which contains a list of SDL files #108

tsunammis opened this issue Jan 29, 2019 · 3 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@tsunammis
Copy link
Contributor

Hello,

The engine should be able to load the SDL from 4 ways.

  • Directly from a string
  • From a list of files
  • From a list of directories
  • From a tartiflette.Schema object

As specified in the API.

When the sdl parameter targets a folder.

Every file which ends by .sdl will be concatenated, in lexicographical order.

import tartiflette

engine = tartiflette.Engine(
    "/User/chuck/workspace/mytartiflette"
)

If I try to load the SDL from a directory, I get an exception.

  • Tartiflette version: 0.3.4
  • Python version: 3.7.1
  • Executed in docker: No
  • GraphQL Schema & Query: c.f below
  • Stacktrace c.f below

app.py

import os
from tartiflette import Resolver, Engine

@Resolver("Mobility.parkings")
async def resolver_hello(parent, args, ctx, info):
    pass

engine = Engine(
    os.path.dirname(os.path.abspath(__file__)) + "/sdl"
)

SDL

./sdl/default.gql

type Query {
  mobility: Mobility
}

type Mobility {
  parkings(offset: Int, limit: Int): [Parking]
}

type Parking {
  id: String
  name: String
  location: Location
  parkingSpace: ParkingSpace
}

type ParkingSpace {
  total: Int
  currentlyAvailable: Int
}

type Location {
  latitude: Float
  longitude: Float
}

Stacktrace

Traceback (most recent call last):
  File "/Users/s.chollet/.local/share/virtualenvs/open-data-graphql-orleans-kWiDIuqs/lib/python3.7/site-packages/tartiflette/schema/schema.py", line 255, in get_field_by_name
    return self._gql_types[object_name].find_field(field_name)
KeyError: 'Mobility'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/s.chollet/workspace/p/life/projects/open-data-graphql-orleans/open_data_orleans/__main__.py", line 4, in <module>
    from open_data_orleans.app import run
  File "/Users/s.chollet/workspace/p/life/projects/open-data-graphql-orleans/open_data_orleans/app.py", line 43, in <module>
    os.path.dirname(os.path.abspath(__file__)) + "/sdl"
  File "/Users/s.chollet/.local/share/virtualenvs/open-data-graphql-orleans-kWiDIuqs/lib/python3.7/site-packages/tartiflette/engine.py", line 26, in __init__
    schema_name, custom_default_resolver, exclude_builtins_scalars
  File "/Users/s.chollet/.local/share/virtualenvs/open-data-graphql-orleans-kWiDIuqs/lib/python3.7/site-packages/tartiflette/schema/bakery.py", line 37, in bake
    schema = SchemaBakery._preheat(schema_name, exclude_builtins_scalars)
  File "/Users/s.chollet/.local/share/virtualenvs/open-data-graphql-orleans-kWiDIuqs/lib/python3.7/site-packages/tartiflette/schema/bakery.py", line 25, in _preheat
    obj.bake(schema)
  File "/Users/s.chollet/.local/share/virtualenvs/open-data-graphql-orleans-kWiDIuqs/lib/python3.7/site-packages/tartiflette/resolver/resolver.py", line 46, in bake
    field = schema.get_field_by_name(self._name)
  File "/Users/s.chollet/.local/share/virtualenvs/open-data-graphql-orleans-kWiDIuqs/lib/python3.7/site-packages/tartiflette/schema/schema.py", line 258, in get_field_by_name
    "field `{}` was not found in GraphQL schema.".format(name)
tartiflette.types.exceptions.tartiflette.UnknownSchemaFieldResolver: field `Mobility.parkings` was not found in GraphQL schema.
@abusi
Copy link
Contributor

abusi commented Jan 29, 2019

Hum, strange, i'll look into it. Thanks for the bug report.

@abusi abusi added this to the road-to-v1 milestone Jan 29, 2019
@Maximilien-R
Copy link
Member

Maximilien-R commented Jan 29, 2019

Hi @tsunammis,

As specified in the documentation:
https://github.com/dailymotion/tartiflette/blob/e9d73f9a710bb7c6f6fa7f26d061d0dee0087df2/docs/API.md#L57-L59

When the SDL parameter refers to a directory path, only files with an .sdl extension are read and concatenated. According to your example, your ./sdl directory only contains a default.gql file which doesn't have the appropriate extension (which means that it's not read and your types aren't recognized by the Tartiflette engine).

Currently, .sdl is the only supported file extension when the SDL parameter refers to a directory path. Maybe we should support a more exaustive list (including adding support for .gql and / or .graphql)?

In addition we could also raise an error at the Tartiflette engine initialization when the processing of the SDL parameter ends up returning an empty SDL (which is the case here).

@tsunammis
Copy link
Contributor Author

@abusi @Maximilien-R Thanks.

We will have to support the most common extension, .graphql

In addition we could also raise an error at the Tartiflette engine initialization when the processing of the SDL parameter ends up returning an empty SDL (which is the case here).

Good idea 👍

@abusi abusi added the enhancement New feature or request label Jan 29, 2019
@abusi abusi assigned abusi and unassigned Maximilien-R Jan 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants