We have a headless application running on Enonic XP. We would like to use the XP server for time synchronization on client side.
Is there any change to select the server current time by GraphQL via Guillotine API?
Guillotine API is a headless content API. It is technically possible to create a content that would report server time, but would be awkward.
You could instead extend GraphQL schema
var schema = guillotineLib.createSchema({
creationCallbacks: {
'Query': function (context, params) {
params.fields.getServerTime = {
type: graphQlLib.GraphQLString,
resolve: function (env) {
return Java.type('java.time.LocalDateTime').now()
}
};
}
}
}
);
Hi Pavel,
You can customize a schema using creationCallbacks as in the example in the previous reply. More details you can find here
But in your case I suggest to implement ScriptBean helper which will return server time in your application.
Java:
public class ServerTimeHelper implements ScriptBean {
@Override
public void initialize( final BeanContext context )
{
}
public long getTime() {
return new Date().getTime();
}
}
JS:
var bean = __.newBean('com.project.ServerTimeHelper');
bean.getTime();