On 2022-05-09 10:49 pm, Matt Goldberg wrote:
A couple follow up questions on this:

 1. If I wanted to customize the message added to the change
    associated with running a script, is the easiest way to use
    graph.transaction?

Yes, it's the only clean way. A script can also make multiple changes to different graphs, and thus produce multiple log messages.

 1. What is the easiest way to validate that any changes produced by
    running a script do not violate any SHACL constraints before
    actually making the changes, like how strict=true prevents GraphQL
    changes if there are issues?

See the documentation of graph.transaction:

/**
     * Temporarily switches the active data graph to a given named graph and executes a function with that active graph.
     * The new graph will also become the default graph of SPARQL queries.
     * After the function has been executed, the previously active data graph will become active again.
     * The result of the transaction call is the result of its callback.
     * Assuming the script is not executed in read-only mode, the inner graph is writable.      * The system will activate a "diff graph" that collects all changes, and features such as graph.changes can be used.      * At the end of the transaction, the changes will be committed, unless no changes have been made.      * Use graph.changes.rollBack() at the end of a transaction in case you want to make sure that no changes will be committed.      * @param{string|NamedNode}graphURI- the URI of the named graph that the transaction should be applied to      * @param{?string}logMessage- a log message for the change history, or null for an automatically generated message      * @param{function}callback- a function (that has no parameters) that will be called (immediately)
     * @returns{?*}the result of the callback
     */

In particular you can use graph.changes.rollBack():

You can call graph.changes.rollBack() based on the outcome of tbs.validate()

letresults = tbs.validate()
if(results.length > 0) {
    graph.changes.rollBack()
}

HTH
Holger


Thanks!

On Tuesday, April 5, 2022 at 7:45:59 PM UTC-4 Holger Knublauch wrote:


    On 2022-04-06 9:37 am, Matt Goldberg wrote:

    Agreed, ADS is more flexible. But for simple things it's
    convenient to be able to go through GraphQL since it's less work,
    especially since it is hooked into SHACL validation and the
    Teamwork change history.

    FYI ADS is also using SHACL validation and the change history.
    That's how the Preview button on the Script Editor panel is
    implemented.

    Holger



    I'll either use ADS or generate URIs externally in the meantime.

    Thanks!
    On Tuesday, April 5, 2022 at 7:13:50 PM UTC-4 Holger Knublauch wrote:

        Hello Matt,

        correct, this isn't supported at the moment, and you're right
        it should work in principle. I have recorded an internal
        development ticket (TBS-4783) for a future version.

        Meanwhile, if that's an option, you could use JavaScript/ADS
        scripting for similar purposes, with a similar syntax. ADS
        includes a function graph.newURI(type) that will look at the
        URI construction rules.

        leturi = graph.newURI(g.City);
        let newCity = g.createCity({
            uri: uri,
            prefLabel: 'Hagen',
            altLabel: 'Das Tor zum Sauerland'
        })

        The advantage here over GraphQL is that you can actually DO
        something with the generated URIs because you can assign them
        to variables and use those variables in other places, e.g. to
        define further references:

        someCountry.capital = newCity;

        GraphQL would be a bit of a one-way-street where you can
        create instances but then would need to make additional
        queries to process the newly generated instances. In the case
        of auto-generated URIs you wouldn't even know what those
        generated URIs are.

        Holger


        On 2022-04-06 2:36 am, Matt Goldberg wrote:
        Hello-

        I've been working with the GraphQL API to programmatically
        create and modify resources. If I create a new resource and
        do not provide a URI, I expected that the generated
        identifier would be a URI created using the Asset
        Collection's configured URI Construction Rules in the Manage
        tab. However, it created a blank node instead. I couldn't
        find a way in the documentation to have it use the URI
        Construction Rules instead. Is that an option somewhere, or
        must the caller be responsible for generating a URI if a
        blank node is not desired?

        Thanks!
-- You received this message because you are subscribed to the
        Google Groups "TopBraid Suite Users" group.
        To unsubscribe from this group and stop receiving emails
        from it, send an email to [email protected].
        To view this discussion on the web visit
        
https://groups.google.com/d/msgid/topbraid-users/a6e70516-dc62-4f82-9d12-b2fca1d97b55n%40googlegroups.com
        
<https://groups.google.com/d/msgid/topbraid-users/a6e70516-dc62-4f82-9d12-b2fca1d97b55n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- You received this message because you are subscribed to the
    Google Groups "TopBraid Suite Users" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to [email protected].
    To view this discussion on the web visit
    
https://groups.google.com/d/msgid/topbraid-users/71bd0b75-7203-4025-bbbb-927d385b3dbbn%40googlegroups.com
    
<https://groups.google.com/d/msgid/topbraid-users/71bd0b75-7203-4025-bbbb-927d385b3dbbn%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/5681eae0-42f0-4c8c-afc1-1696fdccda15n%40googlegroups.com <https://groups.google.com/d/msgid/topbraid-users/5681eae0-42f0-4c8c-afc1-1696fdccda15n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "TopBraid 
Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/topbraid-users/120e74bc-32e3-67bb-5dae-4508966adb98%40topquadrant.com.

Reply via email to