Comments (7)
Hi,
Thanks - glad you like the library!
We're waiting for servant-foreign
to add support for the AuthProtect
combinator, then we can think about how to support auth in servant-elm
.
However, if your Elm requests don't need to do anything special (I'm guessing the browser automatically adds your auth cookie to the requests?), in the meantime you can just add an instance for AuthProtect
that does nothing:
instance (KnownSymbol sym, HasForeign lang ftype sublayout)
=> HasForeign lang ftype (AuthProtect sym :> sublayout) where
type Foreign ftype (AuthProtect sym :> sublayout) = Foreign ftype sublayout
foreignFor lang ftype Proxy req =
foreignFor lang ftype (Proxy :: Proxy sublayout) req
from servant-elm.
I just happened to be working on this and using {-# LANGUAGE ScopedTypeVariables #-}
solved the ambiguous type variable problem.
from servant-elm.
Nice! I'll give it a shot and report back. Thanks for the suggestion!
from servant-elm.
Well, I got stuck on an ambiguous type variable problem and was unfortunately at a loss as to how to begin debugging it, but it's alright if this doesn't work because I can just generate the Elm by hand and return to this problem once the servant-foreign
library supports the AuthProtect
combinator.
I'll post my attempt and the compiler error anyway in case anyone is working on something similar and stumbles across this discussion:
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
import Data.List
import Data.Proxy
import GHC.TypeLits (KnownSymbol)
import Servant.Elm
import Servant.Foreign
import Api
instance (KnownSymbol sym, HasForeign lang ftype sublayout)
=> HasForeign lang ftype (AuthProtect sym :> sublayout) where
type Foreign ftype (AuthProtect sym :> sublayout) = Foreign ftype sublayout
foreignFor lang ftype Proxy req =
foreignFor lang ftype (Proxy :: Proxy sublayout) req
Results in:
• Couldn't match type ‘Foreign ftype api0’
with ‘Foreign ftype sublayout’
Expected type: Foreign ftype (AuthProtect sym :> sublayout)
Actual type: Foreign ftype api0
NB: ‘Foreign’ is a type function, and may not be injective
The type variable ‘api0’ is ambiguous
• In the expression:
foreignFor lang ftype (Proxy :: Proxy sublayout) req
In an equation for ‘foreignFor’:
foreignFor lang ftype Proxy req
= foreignFor lang ftype (Proxy :: Proxy sublayout) req
In the instance declaration for
‘HasForeign lang ftype (AuthProtect sym :> sublayout)’
• Relevant bindings include
req :: Req ftype (bound at client/GenerateElm.hs:19:33)
ftype :: Proxy ftype (bound at client/GenerateElm.hs:19:21)
foreignFor :: Proxy lang
-> Proxy ftype
-> Proxy (AuthProtect sym :> sublayout)
-> Req ftype
-> Foreign ftype (AuthProtect sym :> sublayout)
(bound at client/GenerateElm.hs:19:5)
from servant-elm.
@garetht's suggestion worked for me.
from servant-elm.
Great! Sorry, it would have been helpful for me to put the language pragmas and imports in my snippet...
from servant-elm.
Oh, no worries. I should understand the language pragmas better than I do if I'm going to be using them.
from servant-elm.
Related Issues (20)
- Support generate elm api as HttpBuilder ?
- newtype encoding for query param does not match decoding by Servant
- servant-elm-0.4.0.1 test suite failure with servant-0.13 HOT 2
- Use elm-bridge instead of elm-export?
- Creating output directory automatically HOT 2
- Double `Maybe` for a QueryParam? HOT 1
- Upgrade to 0.19 HOT 3
- Expose url construction as an elm function
- Transfer repo to @haskell-servant HOT 9
- Generate BookId instead of (Key Book) for persistent's type aliases HOT 2
- Upgrade README docs according to 0.6.0.0 changes HOT 1
- Clarify that servant-elm does support elm/http 2.0.0 HOT 4
- Don't add a "query_" prefix to query params
- When query param is a bool, Elm code attempts to use String.fromInt on it HOT 5
- generating elm for polymorphic data type and type synonym is broken
- test suite failure with servant-0.18.2 HOT 1
- Custom Aeson instances HOT 1
- Looking for maintainers HOT 6
- Request to release version 0.7.3 that includes fix of broken tests HOT 1
- Support for named routes in servant HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from servant-elm.