Skip to content

Commit

Permalink
Fixes supabase-community#37 - Return Type minimal would fail to res…
Browse files Browse the repository at this point in the history
…olve because of incorrect `Accept` headers. Added header and test to verify for future.
  • Loading branch information
acupofjose committed Dec 27, 2021
1 parent 24f80fe commit 44d4bf6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
13 changes: 9 additions & 4 deletions Postgrest/QueryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public enum DuplicateResolutionType

public Dictionary<string, string> ToHeaders()
{
var headers = new Dictionary<string, string>();
var prefersHeaders = new List<string>();

if (Upsert)
Expand All @@ -78,10 +79,14 @@ public Dictionary<string, string> ToHeaders()
prefersHeaders.Add($"count={countAttr.Mapping}");
}

return new Dictionary<string, string>
headers.Add("Prefer", String.Join(",", prefersHeaders.ToArray()));

if (Returning == ReturnType.Minimal)
{
{ "Prefer", String.Join(",", prefersHeaders.ToArray()) }
};
headers.Add("Accept", "*/*");
}

return headers;
}
}
}
}
2 changes: 1 addition & 1 deletion Postgrest/Responses/ModeledResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ModeledResponse(BaseResponse baseResponse, JsonSerializerSettings seriali
Content = baseResponse.Content;
ResponseMessage = baseResponse.ResponseMessage;

if (shouldParse)
if (shouldParse && !string.IsNullOrEmpty(Content))
{
var token = JToken.Parse(Content);

Expand Down
7 changes: 6 additions & 1 deletion PostgrestTests/ClientApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ public async Task TestBasicInsert()
Assert.AreEqual(newUser.Status, insertedUser.Status);

await client.Table<User>().Delete(newUser);

var response2 = await client.Table<User>().Insert(newUser, new QueryOptions { Returning = QueryOptions.ReturnType.Minimal });
Assert.AreEqual("", response2.Content);

await client.Table<User>().Delete(newUser);
}

[TestMethod("insert: headers generated")]
Expand Down Expand Up @@ -938,13 +943,13 @@ public async Task TestInsertBulk()
AgeRange = new IntRange(21, 28),
Status = "OFFLINE"
};

var users = new List<User>
{
rocketUser,
aceUser
};


var response = await client.Table<User>().Insert(users);
var insertedUsers = response.Models;

Expand Down

0 comments on commit 44d4bf6

Please sign in to comment.