fortunejs / fortune-json-api

JSON API serializer for Fortune.
MIT License
63 stars 28 forks source link

Include with Options GET Query Paramaters #76

Open brandonmikeska opened 3 years ago

brandonmikeska commented 3 years ago

Hey!

Trying to build a salesforce adapter and most of it is working well. I am trying to figure out how to specify the fields with the include.

I see you have a closed issue that talks about doing the following: inlude={type.field}

When I try this I get the invalid link so I know my adapter isn't doing something correct. Any pointers would be awesome!

Here's my store

"use strict";

const fortune = require("fortune");
const salesforceAdapter = require("./adapters/sf-jsonapi-salesforce-handler/salesforceAdapter");

const resources = {
  Account: {
    Name: String,
    Type: String,
    CreatedDate: String,
    Contacts: [Array("Contact"), "Account"],
    Parent: "Account",
    CreatedBy: "User",
    LastModifiedBy: "User",
  },
  Contact: {
    Name: String,
    Title: Number,
    Account: ["Account", "Contacts"],
    CreatedBy: "User",
  },
  User: {
    FirstName: String,
    LastName: String,
  },
};

const hooks = {};

const options = {
  adapter: [
    salesforceAdapter,
    {
      sfURL: "****",
      sfUserName: "****",
      sfPassword: "****",
      apiVersion: "51.0",
    },
  ],
  hooks,
};

const store = fortune(resources, options);

var originalRequest = store.request;
store.request = function (opts) {
  return originalRequest.call(this, opts);
};

module.exports = store;

Here's the request

http://localhost:5000/api/accounts?include=CreatedBy.FirstName

Here's the response

{
  "jsonapi": {
    "version": "1.0"
  },
  "errors": [
    {
      "title": "BadRequestError",
      "detail": "The field \"FirstName\" does not define a link."
    }
  ]
}
brandonmikeska commented 3 years ago

Actually I solved this with my custom adapter but I noticed the latest NPM package is not the same as in master. Is there a planned release version that will include the relationship changes that are on master?