View more context

 

sander_ha
  1. SilverStripe\GraphQL\Manager.default:
  2. properties:
  3. Middlewares:
  4. ### Disable auto CSRF protection because we will use JWT security
  5. CSRFMiddleware: false # TODO currently not working

Doesnt work either

sander_ha

Yes like this:

  1. SilverStripe\Core\Injector\Injector:
  2. SilverStripe\GraphQL\Manager.default:
  3. properties:
  4. Middlewares:
  5. ### Disable auto CSRF protection because we will use JWT security
  6. CSRFMiddleware: false
reimerwilliam

Hello! @unclecheese @sander_ha We are trying to disable the CSRFMiddleware since we want to use JWT but we still get the error Mutations must provide a CSRF token in the X-CSRF-TOKEN header

  1. SilverStripe\Core\Injector\Injector:
  2. SilverStripe\GraphQL\Manager.default:
  3. properties:
  4. Middlewares:
  5. CSRFMiddleware: false

Tried above but still get the error

Also tried with `After: '#graphqlconfig'``

sander_ha

@reimerwilliam My setup is like this, not much else I can help you with really:

  1. ---
  2. Name: api-graphql
  3. After:
  4. - '#graphqlconfig'
  5. ---
  6.  
  7. ### Expose endpoint
  8. SilverStripe\Control\Director:
  9. rules:
  10. 'graphql': '%$SilverStripe\GraphQL\Controller.default'
  11.  
  12. SilverStripe\Core\Injector\Injector:
  13. SilverStripe\GraphQL\Manager.default:
  14. properties:
  15. Middlewares:
  16. ### Disable auto CSRF protection because we will use JWT security
  17. CSRFMiddleware: false
👍 (1)
reimerwilliam

Thanks for the reply, may I ask what version of Silverstripe and GraphQL you are running?

sander_ha

I'm back with another question! This section simply says "TODO" : https://github.com/silverstripe/silverstripe-graphql#define-input-types Does that mean that you can define an Object type as input type?

Show 1 attachment(s)
GitHub  
silverstripe/silverstripe-graphql

Serves SilverStripe data as GraphQL representations - silverstripe/silverstripe-graphql

Hide attachment content
sander_ha

Trying to do this for a mutator:

  1. public function args(): array
  2. {
  3. return [
  4. 'Order' => ['type' => $this->manager->getType('Order')]
  5. ];
  6. }
sander_ha

Ah, a specific "OrderInput" type must be defined with this snippet on it:

  1. protected $inputObject = true;
unclecheese

yeah, probably says TODO because it's such a simple thing to document that no one wants to bother 🙂

null

I have a method that's supposed to return a DataObject but GraphQL is casting it to a string with the classname. Is there a whitelist or something where I have to define a type?

unclecheese
  1. public function myGetter(): GalleryImage
  2. {
  3. return GalleryImage::get()->filter('some', filter');
  4. }
null

So I have this getter, something along the lines of getSomeSpecificTaskSubmission() that returns a TaskSubmission dataobject.

null

If I call SomeSpecificTaskSubmission through GraphQL, it returns the string Name\Space\TaskSubmission instead of my TaskSubmission object

unclecheese

what happens when you call $myObj->obj('SomeSpecificTaskSubmission')

null

kind of like when you echo $someDataobject, it casts to a string

null

How would I do that? I pass in text via a GraphQL query. At no point do I invoke the object code

null

if I var_dump my object before returning it, I get what you'd expect - a TaskSubmission dataobject

unclecheese

so here is where it should be taking note that you've added a field that requires another type to be creahttps://github.com/silverstripe/silverstripe-graphql/blob/3/src/Scaffolding/Scaffolders/DataObjectScaffolder.php#L623

Show 1 attachment(s)
GitHub  
silverstripe/silverstripe-graphql

Serves SilverStripe data as GraphQL representations - silverstripe/silverstripe-graphql

Hide attachment content
null

See, it actually goes deeper... in that same query, there's QuestionnaireSubmission. It's just like the TaskSubmission, but it's a questionnaire. It doesn't have this problem - it returns as an object

null

It's almost like there's a whitelist, and my TaskSubmission friend isn't on it

unclecheese

so you have two dataobject getters. one works, one doesn't?

null

No - that one isn't a getter. it's a has_one relationship to TaskSubmission. You might consider it to be a parent

null

hrm... I wonder if private static $casting will work

null

hmm... can I use $casting to cast to a dataobject? I thought it was just for fieldtypes

unclecheese

What does $myObj->obj('SomeSpecificTaskSubmission') return?

unclecheese

what about MyObject::singleton()->obj('SomeSpecificTaskSubmission')

unclecheese

any chance the method would return null on a singleton?

null

I'm not sure where to place that code to get it to execute

unclecheese

Your getters have to be deterministic. Otherwise GraphQL can't type them.

unclecheese

just chuck it in a controller init function or someting

unclecheese

I would do ->exists() ? ->first() : TaskSubmission::create()

unclecheese

it's a bit shit. there's an open PR for explicitly typing getters

null

$data->obj('SomeSpecificTaskSubmission') does indeed return a TaskSubmission object

null

I have xdebug, it makes pretty errors slowly 😄

null

So funny story, it's not actually the SomeSpecificTaskSubmission object I need. What I really need, after that call, is a particular string on that object. it's a piece of JSON on the dataobject itself.

I thought I'd get clever, and make a getter that calls a getter, to return that string instead.

That getter should return the same object, then $whatever->MyString should return that string. It doesn't though... accessing it via GraphQL won't query the siblings at all. The relationship gets destroyed, and $whatever->MyString throw's its toys because I'm accessing a property on a non-object

unclecheese

so by default, when a dataobject gets implicitly added to your schema (e.g. through an exposed getter), all you get is ID on that object.

unclecheese

Otherwise, the scaffolder would be too eagerly exposing your data without you really knowing.

unclecheese

You have to explicitly expose anything beyond ID.

null

Why does it cast as a string to the class name though? You'd think it'd just return the ID?

null

It's weird, if I name the getter anything other than getSomeSpecificTaskSubmission() it craps itself. Which means if I name it getSomeSpecificTaskSubmissionMyString it fails.

My solution was a method called getSomeSpecificTaskSubmission() that returns a string instead of an object (as the name might imply), and a lot of salty comments explaining the behaviour

null

@unclecheese you mentioned an open PR for the explicitly defining types on the getter... do you have a link to that? https://silverstripe-users.slack.com/archives/C39NVTQNQ/p1568943077055600?thread_ts=1568939613.046600&cid=C39NVTQNQ

Show 1 attachment(s)
Aaron Carlino

it's a bit shit. there's an open PR for explicitly typing getters

Hide attachment content
Scopey

https://github.com/silverstripe/silverstripe-graphql/pull/188

Show 1 attachment(s)
GitHub  
API Scaffolders can now be more expressive when registering fields by ScopeyNZ · Pull Request #188 · silverstripe/silverstripe-graphql

This adds the ability to register a new FieldDefinition when adding fields with a scaffolder. This means you can explicitly specify the type AND the resolver for the field rather than relying on it...

Hide attachment content
Scopey

We closed it as it was getting a little crazy and there was a "this might all change in 4" sentiment too


Show less replies