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

Add queryable interfaces #30

Merged
merged 21 commits into from
Feb 17, 2022
Merged

Add queryable interfaces #30

merged 21 commits into from
Feb 17, 2022

Conversation

rubensworks
Copy link
Member

This PR implements the latest state of the new query spec as defined in https://github.com/rdfjs/query-spec/

This PR should not be merged yet into master until the query spec is stable.
In the meantime, prereleases of this package are being published to npm for testing purposes.
At the time of writing 1.1.0-next.0 of @rdfjs/types is available on npm.

@jacoscaz I changed some small things while experimenting with these interfaces in Comunica. Nothing major was changed, just some things to simplify the implementation of them.
All interfaces (except for the filterable ones) have been implemented in Comunica, and have been confirmed to work as intended.

@changeset-bot
Copy link

changeset-bot bot commented Feb 3, 2022

🦋 Changeset detected

Latest commit: 09ad631

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@rdfjs/types Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@jacoscaz jacoscaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work @rubensworks ! I'm really happy to hear that everything seems to work as intended. I have a few comments but only one of them is significant.

query/common.d.ts Show resolved Hide resolved
query/common.d.ts Show resolved Hide resolved
query/common.d.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@jacoscaz jacoscaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I wouldn't merge, yet, but looks good.

@rubensworks
Copy link
Member Author

No indeed, won't merge yet. Just published 1.1.0-next.1 for whoever is interested.

@rubensworks
Copy link
Member Author

I've removed the filterable interfaces from this PR for now into #31, since no implementations of this interface exist yet, and it may take a longer time to stabilize.

This PR has been open for a week now.
Unless there are any objections, I'll wait another week (until February 17) to merge this.

@rubensworks
Copy link
Member Author

Pinging some people who may want to have another look at this: @gsvarovsky @tpluscode

Copy link
Contributor

@tpluscode tpluscode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize I come late to the party, since I was not actively participating in this PR. Sorry if you might find my comment a little disruptive of your effort.

I envisioned that I would have an immediate use for it but I gotta share some observations. My biggest beef is with the Bindings interface. Please see the individual code comments

query/queryable.d.ts Show resolved Hide resolved
query/queryable.d.ts Outdated Show resolved Hide resolved
query/queryable.d.ts Show resolved Hide resolved
query/queryable.d.ts Outdated Show resolved Hide resolved
Comment on lines 115 to 139
> = unknown
& (SupportedResultType extends BindingsResultSupport ? {
queryBindings<QueryFormatType extends QueryFormatTypesAvailable>(
query: QueryFormatType,
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType,
): Promise<ResultStream<Bindings>>;
} : unknown)
& (SupportedResultType extends BooleanResultSupport ? {
queryBoolean<QueryFormatType extends QueryFormatTypesAvailable>(
query: QueryFormatType,
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType,
): Promise<boolean>;
} : unknown)
& (SupportedResultType extends QuadsResultSupport ? {
queryQuads<QueryFormatType extends QueryFormatTypesAvailable>(
query: QueryFormatType,
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType,
): Promise<ResultStream<RDF.Quad>>;
} : unknown)
& (SupportedResultType extends VoidResultSupport ? {
queryVoid<QueryFormatType extends QueryFormatTypesAvailable>(
query: QueryFormatType,
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType,
): Promise<void>;
} : unknown)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone else finds the queryX methods names a little awkward?

If this is a SPARQL query interface, how about renaming them to their query form counterparts? For example as they are called in sparql-http-client

Suggested change
> = unknown
& (SupportedResultType extends BindingsResultSupport ? {
queryBindings<QueryFormatType extends QueryFormatTypesAvailable>(
query: QueryFormatType,
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType,
): Promise<ResultStream<Bindings>>;
} : unknown)
& (SupportedResultType extends BooleanResultSupport ? {
queryBoolean<QueryFormatType extends QueryFormatTypesAvailable>(
query: QueryFormatType,
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType,
): Promise<boolean>;
} : unknown)
& (SupportedResultType extends QuadsResultSupport ? {
queryQuads<QueryFormatType extends QueryFormatTypesAvailable>(
query: QueryFormatType,
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType,
): Promise<ResultStream<RDF.Quad>>;
} : unknown)
& (SupportedResultType extends VoidResultSupport ? {
queryVoid<QueryFormatType extends QueryFormatTypesAvailable>(
query: QueryFormatType,
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType,
): Promise<void>;
} : unknown)
> = unknown
& (SupportedResultType extends BindingsResultSupport ? {
select<QueryFormatType extends QueryFormatTypesAvailable>(
query: QueryFormatType,
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType,
): Promise<ResultStream<Bindings>>;
} : unknown)
& (SupportedResultType extends BooleanResultSupport ? {
ask<QueryFormatType extends QueryFormatTypesAvailable>(
query: QueryFormatType,
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType,
): Promise<boolean>;
} : unknown)
& (SupportedResultType extends QuadsResultSupport ? {
construct<QueryFormatType extends QueryFormatTypesAvailable>(
query: QueryFormatType,
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType,
): Promise<ResultStream<RDF.Quad>>;
} : unknown)
& (SupportedResultType extends VoidResultSupport ? {
update<QueryFormatType extends QueryFormatTypesAvailable>(
query: QueryFormatType,
context?: QueryFormatType extends string ? QueryStringContextType : QueryAlgebraContextType,
): Promise<void>;
} : unknown)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was also a long discussion about this one here: rdfjs/query-spec#7

Eventually, we reached a consensus about the current methods.
(I don't remember the exact argumentation, perhaps @jacoscaz or @gsvarovsky knows?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do remember the argumentation but it originated from the question of whether to have these type-specific methods at all. Now that we do have them in the spec, this looks like an interesting change to me. Or at least I cannot come up with a strong argument against this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinion on this myself, I would be fine with this change. I think @gsvarovsky had some concerns about this.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm definitely in favour of more fluent method names. My only reservation is that these methods obtain a query object/proxy but don't execute it. But at this point that's probably splitting hairs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we all agree on having these methods return results directly, without an intermediate Query object, then we might also agree on changing their names as per @tpluscode's suggestion. Anyone against this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just remembered a (significant) reason to keep the query... methods: interface discovery through autocompletion.

Since the Queryable interface already exposes a query method, developers that don't need the API docs might start typing query... in their editor. Smart editors would then immediately also suggest queryBindings, queryQuads, ... This would help developers get directed to the simpler query methods from the SparqlQueryable interface if they are available.

If we would go for select, construct, etc, then we have to take into account the fact that construct might cause some confusion, since we don't have a 1-1 mapping with the SPARQL query clauses. Namely, construct would be used for both CONSTRUCT and DESCRIBE query clauses, which may not be obvious for newcomers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if were to go with renaming to select, construct, ... then we should also have a describe, which in the majority of cases would probably call construct internally. I guess on one side we would favor discovery by autocompletion, on the other side we would favor discovery by intuition. I can see the point in both approaches, happy to go with either.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another (minor) argument in favor of query... is the alignment with the resultType field of Query.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All told, there seem to be more arguments in favor of keeping these methods as they are. I think we can resolve this and proceed with merging.

query/queryable.d.ts Outdated Show resolved Hide resolved
query/common.d.ts Show resolved Hide resolved
Copy link
Contributor

@tpluscode tpluscode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing thought: for a large PR with many new pieces, it would be wise to add some tests :)

@@ -0,0 +1,13 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha! This will be the real last comment. Should the pre take be removed or are you intending another prerelease?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will remove.

@rubensworks
Copy link
Member Author

Closing thought: for a large PR with many new pieces, it would be wise to add some tests :)

Right, will look into that.

query/queryable.d.ts Outdated Show resolved Hide resolved
@rubensworks
Copy link
Member Author

I just added some tests (I didn't aim for full coverage though, just the most critical parts for now)

@rubensworks
Copy link
Member Author

All issues should be resolved now. Unless there are any other comments, I'll merge this on Thursday (after fixing the changelog).

@rubensworks rubensworks merged commit 1a557ee into master Feb 17, 2022
@rubensworks rubensworks deleted the feature/query branch February 17, 2022 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants