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

Issue with schema #694

Closed
abourget opened this issue Feb 21, 2018 · 6 comments
Closed

Issue with schema #694

abourget opened this issue Feb 21, 2018 · 6 comments
Assignees
Milestone

Comments

@abourget
Copy link

Hi there, I've been searching for a bit of time now, a way to have this code work:

package broken

import (
	"testing"

	"github.com/cayleygraph/cayley"
	"github.com/cayleygraph/cayley/quad"
	"github.com/cayleygraph/cayley/schema"
	"github.com/stretchr/testify/assert"
)

func TestBroken(t *testing.T) {
	store, err := cayley.NewMemoryGraph()
	assert.NoError(t, err)
	store.AddQuad(quad.Quad{quad.IRI("dialect-source-file.raml#vocabularies/validation"), quad.IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), quad.IRI("http://raml.org/vocabularies/meta#External"), nil})
	store.AddQuad(quad.Quad{quad.IRI("dialect-source-file.raml#vocabularies/validation"), quad.IRI("http://raml.org/vocabularies/meta#name"), quad.String("validation"), nil})
	store.AddQuad(quad.Quad{quad.IRI("dialect-source-file.raml#vocabularies/validation"), quad.IRI("http://raml.org/vocabularies/meta#uri"), quad.String("../vocabulary/validation.raml"), nil})

	schema.RegisterType(quad.IRI("http://raml.org/vocabularies/meta#External"), DialectExternal{})

	var dst DialectExternal
	assert.NoError(t, schema.LoadTo(nil, store, &dst, quad.IRI("dialect-source-file.raml#vocabularies/validation")))
	assert.Equal(t, "validation", dst.Name)
}

type DialectExternal struct {
	// rdfType struct{} `quad:"@type > http://raml.org/vocabularies/meta#External"`
	// ID      quad.IRI `quad:"@id"`
	Name    string   `quad:"http://raml.org/vocabularies/meta#name,optional"`
	URI     string   `quad:"http://raml.org/vocabularies/meta#uri,optional"`
}

This is using version baf955d

Running go test on that fails.

Anyone has insights ? I might have tripped over https://godoc.org/github.com/cayleygraph/cayley/schema#LoadTo where I read

Predicate IRIs in RDF can have a long namespaces, but they can be written in short form. They will be expanded automatically if namespace prefix is registered within QuadStore or globally via "voc" package. There is also a special predicate name "@type" which is mapped to "rdf:type" IRI.

Is it possible that this is not true ? That somehow Cayley expects the short form to be in the database ?

@abourget
Copy link
Author

@dennwc dennwc self-assigned this Feb 22, 2018
@dennwc dennwc added this to the v0.7.2 milestone Feb 22, 2018
@dennwc
Copy link
Member

dennwc commented Feb 22, 2018

You are right about the short form - schema lib naively assumes that all IRIs match exactly on insert and in struct tags. However, the @type predicate is mapped to a short form, and resolution to full form is not done correctly, I guess.

It's time to do this properly. It will require all quad inserts to resolve to full form, and all queries to resolve their arguments to full form as well. For now, the best place for it is QuadStore.ValueOf and QuadStore.ApplyDeltas.

The downside is that users sometimes prefer to use short form, and now they will see a full form as an output of queries. Always printing short form will lead to the same confusion - written values might be in full form, while short form is returned as output.

@abourget
Copy link
Author

abourget commented Feb 22, 2018 via email

@dennwc
Copy link
Member

dennwc commented Feb 23, 2018

@abourget I think it's the best option for this particular case.

Note that graphql endpoint will still fail the same way (it also uses @type shorthand).

@dennwc
Copy link
Member

dennwc commented Mar 3, 2018

@abourget Feel free to reopen if it does not cover your use case

@abourget
Copy link
Author

abourget commented Mar 4, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants