kobrixinc / fdr

A TypeScript library for building applications with RDF graph data.
https://kobrixinc.github.io/fdr/
MIT License
12 stars 1 forks source link

LocalGraph only uses the global name resolver #9

Closed bruzoopak closed 9 months ago

bruzoopak commented 9 months ago

Removed env: FDR as a parameter in the LocalGraph constructor. Currently there is no use for it, as the user has no way to create an FDR instance. All calls are replaced with calls to fdr.ts: fdr Removed the nameResolver field from LocalGraph. The fdr factories must use the same name resolver to create objects, so a graph with a nameResolver different from fdr.resolver will not work.

bolerio commented 9 months ago

@bruzoopak

If we remove env from the Graph interface (and LocalGraph), there will be way to have multiple environments (with different name resolvers and potentially other configurations or important objects) in the same application. Doesn't seem too big of a price to pay to lift that constraint. Instead of using a global object, we'll have an environment object. It's true that it's not used right now. But say you want to right code that is compatible with multiple such environments in a bigger applications, for example because you want to use a factory or a name resolver. With graph.env you can do that. Without it, you have to use the global fdr which is sort of a default predefined environment, but if you chose not to import it and have several different environments, you can.

Perhaps it feels a bit like over-engineering here, but I thought it doesn't add too much complexity.

For removing the name resolver, that makes more sense yeah...we should have only one place to configure a name resolver, and the environment is the right place to do that. Otherwise, it's confusing for no much benefit.

bruzoopak commented 9 months ago

@bolerio I reinserted the env parameter and made several related changes Before that, an observation: The fdrobject in fdr.ts is the environment in which the graph is created which is currently global but we should design so that in principle we could have several environments in the same application by instantiating the GraphEnvFacade.

The changes are:

  1. I changed the rdfs and fdrmake classes to reuse the fdr object so that we single global environment is reused (in practice that means that resolver and language settings will be respected across the three factories -- it used to be the case that each factory created its own resolver and fdrconfig object)
  2. I added the GraphEnvironment type which is RDF & WithResolver.
  3. I changed the type of the Graph.env field to GraphEnvironment instead of FDR because we use the environment for resolution and it needs to be of type WithResolver